/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

openeuphoria.org/docs/quick_over.html#_3_quickoverview
wiki.haskell.org/Monomorphism_restriction
haskell.org/onlinereport/haskell2010/haskellch4.html#x10-930004.5.5
java.com/en/
benchmarksgame.alioth.debian.org/u64q/which-programs-are-fastest.html
benchmarksgame.alioth.debian.org/why-measure-toy-benchmark-programs.html
twitter.com/SFWRedditImages

Great OP

Why is Ruby so /comfy/?
Also, first for Ruby

Writing a CV.
I wish I was a NEET ;_;

>I wish I was a NEET ;_;
Don't.

>collect welfare
>whole day free to do what ever you want
Being NEET is pretty awesome

If I was a NEET, I wouldn't be able to go on inane holidays. That's my driving force.

SHOULD I LEARN PYTHON OR C++ OR ASSEMBLY PLEASE

Why aren't you programming in Euphoria, /dpt/?

openeuphoria.org/docs/quick_over.html#_3_quickoverview

Since you're asking learn python.

Buy breast implants and sell yourself.

>A high-performance, state-of-the-art interpreter that's significantly faster than conventional interpreters such as Perl and Python.
When you have a bullet point "fast" and it's about you comparing yourself to Perl and Python I don't have much faith in your language.
Nobody chooses this language because it's fast if it's on that scale.

Started learning Haskell using haskellbook (seems to be much better than LYAH so far).

GHCi:
*Main> :t (* 9) 6
(* 9) 6 :: Num a => a


But if I load the same (* 9) 6 from the file:

fun = (* 9) 6


I get:

*Main> :t fun
fun :: Integer


Why?

Until depression kicks in.

If it does die, it will die only because of the lack of developer friendliness

>literally all the time in the world to do anything
>get depressed
You can only choose 1

mruby is the comfiest Ruby.

I wrote my own implementation of the quicksort algorithm. Right now I'm working on some visualization in SDL. It's my first time doing graphics so it may take some time.

Also, what do you guys think of my implementation? i posted it yesterday evening, but the only reaction i got was to change the pivot.
void qsort(void* base, size_t num, size_t size,
int (*compar)(const void*,const void*)){
size_t pivot = num - 1;
size_t i = 0;
while(i < pivot){
if(compar(base + i * size, base + pivot * size) > 0){
size_t j = size;
char tmp;
char *a = (char *)base + i * size;
char *b = (char *)base + pivot * size;
char *c = (char *)base + (--pivot) * size;
while(j--){
tmp = *a;
*a++ = *c;
*c++ = *b;
*b++ = tmp;
}
i--;
}
i++;
}
num = num - pivot;
if(pivot > 1) qsort(base, pivot, size, compar);
if(num > 1) qsort((base + pivot * size), num, size, compar);
return;
}


And here is a slightly shorter version, but for int[] only.
void qsort(int *arr, size_t size){
size_t pivot = size-1;
size_t i = 0;
while(i < pivot){
if(arr[i] > arr[pivot]){
size_t j = pivot-1;
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = arr[pivot];
arr[pivot] = tmp;
pivot = j;
i--;
}
i++;
}
size = size - pivot;
if(pivot > 1) quickSort(arr, pivot);
if(size > 1) quickSort(arr + pivot, size);
return;
}

You don't understand how your brain is wired.

>void* base
>compar(base + i

Oh shit, that is actually pretty cool. I hope it does well.~

This is called the Monomorphism Restriction
You can disable it using the compiler flag
-XNoMonomorphismRestriction
or the pragma (at the top of the file)
{-# LANGUAGE NoMonomorphismRestriction #-}

This is done by default in the REPL, as of a certain GHC version (I forget which).
Basically, it stops the compiler from inferring polymorphic signatures.
(You could explicitly give it a polymorphic signature.)

I don't get what you're trying to say.

You can't do arithmetic on void pointers. The only the reason this works is that gcc treats sizeof(void) as 1, this is not standard.

It should really warn you on -Wall, but only does with -Wpedantic.

And here's a more in-depth explanation:
wiki.haskell.org/Monomorphism_restriction
haskell.org/onlinereport/haskell2010/haskellch4.html#x10-930004.5.5

It isn't a big problem, since you can disable it, or provide an explicit signature.

So i should cast it to a char pointer before doing arithmetic then?

Yes, at the top of you function just do something like:

char *bptr = base;

Then use bptr instead of base in your function, you can also remove all those (char *) casts.

Why don't you listen to eurobeat while koding, /dpt/?

>Assembly as a first language
Truly the patricians way

Because I have much better taste in music

>*faint 'running in the ninties' plays in head*
I should.

why is she shouting?

>had a 17gb eurobeat folder
>accidently deleted the wrong partition while reinstalling windows and deleted it
>channel I pulled them from got killed
LOST INTO THE NIGHT

long time;

heehheehehhe

long long DICK;
teehee

Are there some ghetto, fast, easy to write, somewhat effective copy protection schemes for windows executables?

I've been thinking about appending the hardware id to the end of the executable and just checking for it at runtime

short BENIS;

float likeAButterfly;{/code]

>I've been thinking about appending the hardware id to the end of the executable and just checking for it at runtime
Yeah that seems quick and dirty enough. Very inconvenient for users though.

dumb camelCase poster

short dick;

mmheheh

DUMB FORTRAN POSTER

well theres gonna be like 5 users in a 100km radius so it wouldn't be that inconvenient to "reinstall" the application in case their os crashes or something. yeah i think im going with that

Because it sacrifices performance to maximize abstraction. That's why it's so fucking slow.

maybe ruby should try some of that ZERO COST ABSTRACTION

What's a good name for languages like: XML, JSON, HTML and CSS? Markup languages?

Yes.

Don't forget the FEARLESS CONCURRENCY

programming languages

If I wanted to listen to the same shit over and over, I would just do that.

hax my anus

Okay so people writing web apps because it's the easiest way to write cross platform applications and they can also run on browser so people don't have to install them.
We need to create standardized platform which can be used to run applications without installing them and provide way for people easily browse available applications.
How do we implement it?

sounds like a job for javascript

for i in range(1, 101):
print(i)
if not i%3:
print("Fizz")
if not i%5:
print("Buzz")

.NET

why would you limit yourself to one language?

why wouldnt you want to code in javascript

Hmm, sounds almost like a virtual machine.
I've heard of some language that based itself on portability through a virtual machine.

But I think you're missing a major reason people like webapps. They limit the attack surface to the browser and not the system.

You could run somekind of sandboxed executor on top of the vm

Or we could just sandbox the VM.
Some googling found me this little project:
java.com/en/

Wow, and that language is pretty fast too!
benchmarksgame.alioth.debian.org/u64q/which-programs-are-fastest.html

Reminder that no non-Lisp dynamically typechecked language has ever surpassed a Lisp

Man I hate how people cite that as if it's a measure of performance. Even the authors disagree
benchmarksgame.alioth.debian.org/why-measure-toy-benchmark-programs.html

If you want to get a hint from this look at how the implementations differ from naive solutions outside of algorithmic optimization.
If you look at C you find that most of it is just as you'd normally write C (ignoring some local stack declarations that'd be global or passed in by pointer). If you look at python they write code that's far from what you'd expect real code would be like in Python.

That's what bothers me the most. We need benchmarks that compare normal styles.

After all, what's the point in using Python if you're only going to awkwardly write C in it?

Surpassed in being shit?

Lisps are fast and powerful

Non-lisp dynamic languages are less fast and less powerful

Less curly braces and semicolons
Easier to find an online compiler/interpreter
Python is a good scripting language

Exactly.

JIT'd Assembly?

>Less curly braces and semicolons
The same is true of Haskell and Lisp
>Easier to find an online compiler/interpreter
The same is true of Haskell and Lisp
>Python is a good scripting language
The same is true of Haskell and Lisp

What is a "scripting language"?

c++ all the way. after that any other language will feel like a joke.

>Haskell
>scripting
lmfao

Asking because I have no fucking clue at this point: Why does this C++ code lead to the error "Expected Expression" ?

int ind;
char token;

char num_digit_array[MAX_DIGITS];

std::queue Operator_Queue;
std::stack Number_Stack;

int op_ind = 0; /*Keeps track of the index on the operator stack */

/* iterate while there are characters to be read */
for(ind = 0; (token = expressions[ind]) != '\0'; ind++)
{
if( isdigit(token))
{
printf("Found number: %c\n", token);
int num_array_ind;

/* Iterate while you find more digits of the same # */
for(num_array_ind = 0; isdigit(expressions[ind]); ind++)
{
num_digit_array[num_array_ind] = expressions[ind];
}
Number_Stack.push(s_to_double(num_digit_array) );

This actually looks all ri
>Euphoric
>A remarkably simple, flexible, powerful language definition that is easy to learn and use.
why.jpeg

Spotted the IDE babby.
Why not use gcc or clang which literally tells you compile-time errors instead of using shitty jetbrains.

FUCK i hope you're not a CS major.

Haskell has less annoying punctuation, but Lisp is an endless sea of parens.

Also, neither are good scripting languages.

>tfw Java dev and not being able to compile from CLI

I thought the term had enough of a negative connotation that no one would care. Basically I use it when I want to calculate something that Google calculator can't handle. I'm saying it's good for that.

Java is excusable...I mean you're using Java, so chances are you're a Pajeet. Totally understandable.

It's just javac input_file.java -cp some_library.jar:some_path_with_class_files

Yes, you can script in both.
If you really wanted a weak type system, you could do that too - create a type that can represent everything you're interested in, like a python value or a lisp value or a lua table.

import random

def total(hand):
return sum(hand)-10*(21/sum(hand))

deck=[1,2,3,4,5,6,7,8,9,10]
playerHand=[]
dealerHand=[]
score=False

playerHand.append(deck[random.randint(0,9)])
playerHand.append(deck[random.randint(0,9)])

while True:
print(playerHand)
if input("Hit? (0/1)"):
playerHand.append(deck[random.randint(0,9)])
if sum(playerHand) > 21:
print("Bust")
break
else:
while True:
if sum(dealerHand)total(dealerHand):
print("You win")
elif total(playerHand)

I figured that out after a quick lookup, but I was spoiled by my IDE.

Oh and I'm not saying that a weak type system is better for scripting.

The entire point of a scripting language is to be fast and easy without being unpredictable. There is a reason Perl letting people write programs as line noise didn't prevent it from being adopted.

You can create a DSL using the metaprogramming facilities of both languages. It's disingenuous to suggest they're scripting language. Could be a troll tho, so have an ebin upvote friend! xD

import math

print(math.factorial(100))

feels good listening to 140gib of flac super eurobeat while editing some scripts

Yes, and Haskell is faster than scripting languages and more predictable.
You could even write a library that is closer to what you want.

Library, not DSL.

c++ tho

>Haskell is faster than scripting languages
Fast as in writing, you idiot, not executing.

Reminder that it's only thanks to Apple that we're not all stuck writing apps in Flash and using ActionScript.

Haskell is faster to write, too.

but Actionscript is comfy

well memed

how would I go about a tetris clone

>dude lazy evaluation lmao
No. It's supposed to be annoying to write in exchange for being reasonably sure that it works correctly when it builds without an error.

import tetris

I think you missed a present participle.