/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?


Previous Thread:

Other urls found in this thread:

en.wikipedia.org/wiki/Symbolic_artificial_intelligence
norvig.com/paip-preface.html
news.ycombinator.com/item?id=1803815
blog.chucklefish.org/wayward-tide-technical-details/
destroyallsoftware.com/talks/the-birth-and-death-of-javascript
okmij.org/ftp/Haskell/regions.html
hacklang.org/
twitter.com/AnonBabble

We must go smaller, there has to be a way.

just coded my first rock paper scissors. new to programming so it's literally babbys first program.

>tfw drowning in (You)s

You can shave off two characters by removing a set of extraneous parentheses

d=q=>document.querySelector(q);d("#p"+localStorage["Sup Forums-track-g-"+d("[name=res]").value].match(/(\d+)":1}/)[1]+" input").checked=1;d("#delform").submit()

Actually we can probably just do
d=document.querySelector;d("#p"+localStorage["Sup Forums-track-g-"+d("[name=res]").value].match(/(\d+)":1}/)[1]+" input").checked=1;d("#delform").submit()
For another 6 character savings

Run all but the .submit() part and it throws an error:
>TypeError: 'querySelector' called on an object that does not implement interface Document.

>Uncaught TypeError: Illegal invocation

Huh, weird

Javascript has types?

Can I use Haskell do make vidja?

Haskell is pure, how dare you imagine defiling it like that

dynamically typed =/= untyped

Come on men, almost at 150.

Put your thinking caps on and optimize the shit out of this.

daisuki~

Don't be shy to ask anything to your favorite programming literate!

Probably but both carmack and sweeney dropped the idea.

javascript always had types.

en.wikipedia.org/wiki/Symbolic_artificial_intelligence

norvig.com/paip-preface.html
Note that lisp has been replaced by python since then.
news.ycombinator.com/item?id=1803815

Share the code source, please.

Please use an anime image next time.

they're so weak they may as well not exist

Yes.
blog.chucklefish.org/wayward-tide-technical-details/

but
if (op.image.isAnime == true) will happen!

That said, it's probably better to learn Haskell and apply the ideas in a different language, like Rust. Rust shares a lot of similarities with Haskell, and it even has affine types which are just as good or even better at controlling side effects than monads.

Yes actually, it turns out when you make explicit use of them you get pretty optimised code and an interesting target language, hence asm.js
destroyallsoftware.com/talks/the-birth-and-death-of-javascript

It'd be easier to find the user that said 150 and lynch him so everybody forgets and we can say 160.

>affine types
>better at controlling side effects than monads
No

>rust
>worth using
No

shouldn't you use the isX notation only with a method and not with a variable?

it's actually because they do exist that JavaScript can be this ""weak"".

Why do standard library developers think this shit is acceptable?

== true

Just look at all the gymnastics required for decent resource safety with monads. That particular case is actually what inspired algebraic effects since a monad stack is so damn bad at it.

Meanwhile, it's extremely natural with a substructural type system.

...

everything in the std must start with __ to avoid conflicts.

>all the gymnastics required for decent resource safety with monads
I'm not seeing them.

Affine types don't achieve what monads do, and only serve to make less features first class.

>tfw you started a meme

I'm so proud of myself

How do you match the end of line character in PCRE? I want a character class to contain the end of the string, but the expression probably won't be at the end of the string so I can't use [class]?$.

>avoid conflicts
With fucking what? these are just local/private variables.
They are local fucking variables, a conflict is impossible.

That's shitty design.

I want to have an array of structs inside a struct and I want to be able to realloc it. So:
struct faggot{
int x;
};

struct people{
struct faggot ** ops; //pointer to array of faggots
};

struct people *4channers;
4channers->ops=malloc(sizeof(struct faggot *)); //pointer to the array
*4channers->ops=malloc(10*sizeof(struct faggot)); //the array

//later
4channers->ops=realloc(4channers->ops, 20*sizeof(struct faggot)); //don't mind the lack of error checking

Is this correct? Am I doing something wrong here or is there a problem somewhere else, because im getting a segm fault after i go to access the "x" in this example after a realloc.
Don't mind minor syntax errors i just wrote it in the reply box.

import random

count = 0
comp_count = 0
rules = ('''choose 1 for rock
choose 2 for paper
choose 3 for scissors''')
list = (1, 2, 3)
print (rules)

while True:
user_choice = input('user selection: ')
user_choice = int(user_choice)
comp_choice = random.choice(list)

if user_choice == 1:
if comp_choice == 2:
print('computer wins paper beats rock')
comp_count += 1
print('computer has won ', comp_count, '/', '3')
elif comp_choice == 3:
print('you win rock beats scissors')
count += 1
print('you have won ', count, '/', '3')
else:
print('tie')

if user_choice == 2:
if comp_choice == 1:
print('you win paper beats rock')
comp_count += 1
print('computer has won ', comp_count, '/', '3')
elif comp_choice == 3:
print('you lose scissors beats paper')
count += 1
print('you have won ', count, '/', '3')
else:
print('tie')





if comp_count == 2:
print('computer won 2/3')
break
elif count == 2:
print('player has won 2/3')
break
else:
continue


well it's almost finished. I feel lik ethis could be made into one of them cs grad memes.

For "fairness" and lack of entropy you should have the computer decide before the player.

>4channers->ops=realloc(4channers->ops, 20*sizeof(struct faggot)); //don't mind the lack of error checking

that was supposed to be
*4channers->ops=realloc(*4channers->ops, 20*sizeof(struct faggot)); //don't mind the lack of error checking

Wow guys we did it, we got it under 160 characters!

You don't need pointer to pointer. Everything else is fine.

Too bad we can't tweet it.

>I'm not seeing them.
okmij.org/ftp/Haskell/regions.html
okmij.org/ftp/Haskell/extensible/more.pdf (the part about regions)

>Affine types don't achieve what monads do, and only serve to make less features first class.
Monads are for more than controlling side effects. We've gone over this a million times. Substructural types are better than monads at controlling side effects only; they have nothing to do with the abstraction aspect.

smaller

>all side effects are IO
we've been over this a million times

DELETE THIS

with this compact less than 160 character piece of code

Yes, actually. Using e.g. Either as a monad can't have side effects since it's just an abstraction over pure code.

So I guess IO isn't a side effect then

What?

Is PHP worth learning anymore or should I just go full pajeet mode with java or c#?

>== true

i try to know as little PHP as possible. it rots the brain. sometimes you have to use it though, but in those cases i just learn it for a little while and then try to forget

Somebody will say it's worse than Perl, Python, or Ruby backends.

>shouldn't you use the isX notation only with a method and not with a variable?
Why?

hacklang.org/

why is she so smug

Probably because it's "live" when it determines it.
Seems fine if using for data constructs/APIs.

Everybody has preferences for naming.

if you were an anime girl you'd be smug

Good if (day.time.isAfternoon() == true) to you.

IIRC, this convention was introduced by Java; You are supposed to ask a question to the object which is not really the case if you read a variable. It also make easier to avoid conflict with the inner variable.

class Foo
{
bool open;

public bool isOpen() { return open;}
}

I'm surprised Java didn't just roll with "isOpen" and "getIsOpen" which would be a hell of a lot more consistent.

Would you agree then (...isOpen() == true) is fucking retarded then?

It asks the same question twice. Or more so it asks the question then "REALLY?".

maybe he works at NASA and that's part of their coding safety standards so he did it automatically

And you should also think about interfaces where you can't define any variables.

> == true

Bb.. bbbba...Ba-aka. == true is not kawaii. It's kowai.

Though I think it's appropriate for Halloween.

isIsOpenTrue

S-senpai... I code from there!

you should not think about the underlying data, remember oop is about data abstraction, but only about the purpose of the message.

getX is when you need something
isX is when you need an answer by yes or no.

it's either isOpen or getOpen() but not getIsOpen

Is it a problem to have a field isOpen and a method isOpen?

C#, unsurprisingly, doesn't have this problem because it has properties instead of getters/setters.

source? Besides "I/my (related person) works for NASA :^)"

>all these rudeposters

i do work at nasa though

we use cinnameg

Not him but some languages might auto cast things to compare them to booleans then you're left with unexpected behavior.

Granted at that point you deserve it since you weren't checking the type you're comparing and clearly let something else reach that point.

properties are against the principles of oop. never rely on them. pure evil.

>properties are against the principles of oop
I'll make sure to start using them immediately

>properties are against the principles of oop
Even better, but how the fuck are you coming to that conclusion in the first place? They're just better getters and setters.

Someone explain the OP pic? I guess I mean, can someone explain what it means by abstraction and what the last panel is?

The example should use === then to make it clear.

Dynamically typed languages are still retarded.

NASA's requirements are retarded, and everyone besides the dedicated programmers doesn't give two shits.

Sounds like just a naming convention issue, call the private field _isOpen or similar depending on your convention for private field names.

probably an OOP monstrosity of extensions

delete this

#include
#define x_initial 0
#define y_initial 1

double approx_e(double delta_x) {

double y = y_initial;

for (double x = x_initial; x < 1; x += delta_x) {
y += y * delta_x;
}
return y;
}


int main() {
double delta_x;
printf("Choose delta_x for e approximation: ");
scanf("%lf", &delta_x);
printf("e approximation for delta_X=%lf is: %lf", delta_x, approx_e(delta_x));

return 0;
}


Ai em veri gud mathemater xP

Abstraction means generalizing over certain details so that code can be reused in different contexts.

The last panel is a bunch of random Haskell that isn't all abstraction-related, and out of that entire thing zygohistomorphic prepromorphism is the only example of abstraction gone too far.

>isn't at all abstraction related

so it's like creating classes of things basically?

u r veri bed et koad teg tho cx

whai de buli, aim kyut gorl :(

>inserting the word "at"
Sneaky sausage.

Sort of. Classes generalize over how the thing is used, although that's kind of how things are by default. So classes don't really add any abstraction except when you're doing e.g. subtype polymorphism.

Managed to shave off 1 character.

d=q=>document.querySelector(q);d("#p"+localStorage["Sup Forums-track-g-"+d("[name$=o]").value].match(/(\d+)":1}/)[1]+" input").checked=1;d("#delform").submit()


4 more to go.

>comonads allow you to define either duplicate or extend or both
>monads only allow you to define >>=
FFS Haskell

Hi guys simple question here. Look at this simple program that counts words in a sentence.
// Function to determine if a character is alphabetic

#include
#include
bool alphabetic (const char c)
{
if ( (c >= 'a' && c = 'A' && c

#define x_initial 0
#define y_initial 1

wtf???

Also that's a horrible way to approximate e. All you have to do is remember it
2.718281828459045
That was my password for a while.

>not less than 160 characters
Are you even trying?

>if ( alphabetic(string[i]) == true )
fixed that for you

Forgot to ask the question lmfao. My question is about this for loop:
for ( i = 0; string[i] != '\0'; ++i )
if ( alphabetic(string[i]) )
{
if ( lookingForWord )
{
++wordCount;
lookingForWord = false;
}
}
else
lookingForWord = true;

Why does the function only count the first letter only? I understand that it turns into false after the first letter, but does that mean that it stays false through out the end of the word until someting OTHER than a letter appears? If so, why?

:thinking:

Can I do programming on Windows?

painfully

for (i = 0; string[i] != '\0'; ++i) {
if (alphabetic(string[i])) {
/* ... */
} else {
lookingForWord = true;
}
}

It stays false because the statement lookingForWord = true; can only be reached if alphabetic(string[i]) == false, a.k.a. "something OTHER than a letter appears".

Can I do programming in Assembly?

It would be extremely painful