/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

facebook.github.io/react/):
dataorienteddesign.com/dodmain/
twitter.com/NSFWRedditImage

can a java conniseur please post the most minimal fork/join program to show me how it works? i can't tell what is what in the documentation examples. there's so much java boilerplate and idk what's from something it's important and unrelated to demonstrating fork/join, and what's relevant.

Unemployed Haskell programmer here

first for go is fast

How to make if statements inside if statements?
>>>Python 3.6.1
def ragequit():
print("Opinion discarded.")
print("R"+"E"*69+"!!!")
quit()
def start():
meme = input("Do you like memes?: ")
if meme == "y"or"yes"or"sure"or"yea"or"yeah":
pepe = input("You you like Pepe the frog?: ")
if pepe == "y"or"yes"or"sure"or"yea"or"yeah":
print("You're cool.")
elif pepe == "n"or"no"or"nah"or"na":
ragequit()
else:
print("What?")
elif meme == "n"or"no"or"nah"or"na":
ragequit()
while 1:
start()

No surprise there

How fast are we talking? Can it beat rust?

Rust is not a benchmark of speed m8.
even gc'd languages beat it.

Crosspost from Find me a better, more extensible fizzbuzz than:

(: fizzbuzz (fixnum (list-of (list fixnum symbol)) -> noreturn))
(define (fizzbuzz limit conds)
(for-each (lambda (n)
(let ((unfizzed? (foldl (lambda (acc x)
(if (= 0 (modulo n (car x)))
(begin (display (cadr x))
#f)
acc))
#t
conds)))
(if unfizzed?
(display n)))
(newline))
(iota limit 1)))
You can't.

#;> (fizzbuzz 21 '((3 fizz)(5 buzz)(7 bob)))
1
2
fizz
4
buzz
fizz
bob
8
fizz
buzz
11
fizz
13
bob
fizzbuzz
16
17
fizz
19
buzz
fizzbob

Your doing it the right way. Might need to do: if x == 1 or x ==2, instead of just a long chain, not 100% sure though

but if you compare go to actually fast languages, it loses

maybe you should put all those yeas and nos in a list faggot

What did he mean by this?

which one should i use to avoid the evil else statement?
for(;;)
{
if(cond1)
{
do_stuff();
break;
}
if(cond2)
{
do_other_stuff();
break;
}
.
.
.
}

or
if(cond1)
{
do_stuff();
goto end;
}
if(cond2)
{
do_other_stuff();
goto end;
}
.
.
.
label: end;

>if pepe == "y" or "yes" or "ya" or...
Why not
>if pepe(0) == "y"
???

Go away faggot.

Answer the question

Don't yell at me I just started python yesterday.

if else isnt evil
if, else if, else is

Anyone know if MASM is free to download? If not, what's a good x86 assembler?

regexps are always the answer

import re

yes_re = re.compile('y(es|eah?)?|sure')
no_re = re.compile('n(o|ah?)?')

def start():
meme = input("Do you like memes?: ")
if yes_re.fullmatch(meme):
pepe = input("You you like Pepe the frog?: ")
if yes_re.fullmatch(pepe):
print("You're cool.")
elif no_re.fullmatch(pepe):
ragequit()
else:
print("What?")
else:
ragequit()

nasm

Will waterfox work on my 32 bit system, or do I need 64 bit?

affirmative = ["y","yes"]
if meme in affirmative:
print ('faggot')


also i think
meme == 'a' or meme == 'b' is the right syntax

Used emscripten for the first time this week to evaluate if a work project could be supported in a web browser. The project is an audio signal processing library mostly written by me in C++ (and a bit of C).

That shit is magic. Dropped in a cmake toolchain file, wrote up a quick interface using embind, and everything pretty much just worked. I almost like javascript now that I know I can deploy this way.

Thx user!
import re

yes_re = re.compile('y(es|eah|a|ea|e|ee?)?|sure')
no_re = re.compile('n(o|ah|a?)?')
def ragequit():
print("Opinion discarded.")
print("R"+"E"*69+"!!!")
quit()
def start():
meme = input("Do you like memes?: ")
if yes_re.fullmatch(meme):
pepe = input("You you like Pepe the frog?: ")
if yes_re.fullmatch(pepe):
print("You're cool.")
elif no_re.fullmatch(pepe):
ragequit()
else:
print("What?")
else:
ragequit()
start()

How do you feel about higher order conditional statements?

char *get_filebuffer(const char *path, const char *mode)
{
FILE *fp;
if (!(fp = ((!strcmp(path, "-")) ? stdin : fopen(path, mode))))
return NULL;
fseek(fp, 0, SEEK_END);
unsigned len = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *buf = malloc(sizeof(char) * len + 1);
fread(buf, len, 1, fp);
fclose(fp);
return buf[len] = '\0', buf;
}

>*ptr
>*&ptr
>&*ptr
>**ptr
>**ptr + 3
>*(*ptr)
>*(ptr) + 3
>*(*(ptr + 3) + 3)
WHAT THE FUCK IS THIS SHIT HOW DO YOU EVEN WRAP YOUR GOD DAMN MINDS AROUND THIS SHIT
AAAAAAAAAAAAAAAAAAAAAAAAAAA

It's one of those things where the longer you spend writing C, the more it makes sense, even when they're stupidly clever pointer showboating

There's a tutorial in the OP.

better than java

Is it possible for an embedded language to call it's parent language? Or is this an obvious paradox and I need a dll/so.

Have you loved Lain today, /dpt/?

My Python isn't returning floats as a result of a division by default. What should I do to get those floats?

How would I go about passing parameters to components, then? I inevitably have to check if they're null. At the very least I'd like it if the program didn't segfault and instead did nothing, modified nothing, and maybe complained I'm trying to access something that doesn't exist. All solutions I can think of inevitably take more than one line of code every time I want to modify a single parameter of a component, and that's just cumbersome.

I've done Project Euler problems 1 to 200. You are all little brainlet babbies compared to me. I can see all possible realities at once, and it's terrifying me.

project euler problems are so boring, 99% of them have nothing to do with practical software problems you would ever see in real life

Switch statement

Cast one thing as a float

Does anyone have any good openGL books/pdfs? I'm trying to learn lwjgl but find the lack of documentation overwhelming.

make sure you're using / and not //

That's not true, you'll find most math problems in software somewhere. They are really boring math based projects though.

opengl is such a load of shit, even the officially published blue and red books are garbage, and at best supplemented by random opengl tutorials online

and don't forget libglew because gl is such a pile of shit most graphics drivers only support GL 1.1 functions unless you LITERALLY beg your kernel for the function pointer locations to all the newer GL VBO/VAO functions like like glGenBuffers and glBufferData.

Would it be better to learn Vulcan? OpenGL seems like the only option here.

is vulcan even supported on older hardwar?
opengl is going to be around for a long long time, and the lowest version number that supports the modern GL workflow is supported on machines that date back to 2006, so you're fine.

what are programs/problems that i can do to practice programming? i wanna make something but have no ideas or the little ideas i have are achievable with my current skill set

not achievable i meant

Forget it, I just figured out an even better way. All I had to do was add, inside "effect":
if (this == nullptr) return;

Can someone explain to me why this works even when the object is null? I'm assuming it's because the method is independent from the class, and that it always takes itself as a sort of implicit parameter like in python. So object.effect->makeBlue() is just something like makeBlue(object.effect).

Use the module

Go for a classic. Maze generation and representation can be done a ton of different ways.

>Would it be better to learn Vulcan?
Not as a beginner. Really any major developers will abstract a lot on top of vulkan. That's the only way it's actually usable I don't think you're experienced enough to try that.

vulkan isnt that bad, its just tedious.
t. someone whos never touched OGL

thats undefined behavior.
compilers assume this is always nonnull and may optimize that check out.

% cat /tmp/test.cc;
#include
struct foo {
void bar() {
if (this == nullptr) std::cout

Are you ready, /dpt/?

>or the little ideas i have are not achievable with my current skill set
How do you know you couldn't achieve things?
How would we be able to recommend you things without knowing what you know?
If you're only supposed to do projects using what you know you won't learn. Focus on using something you don't know. Just remember to limit how much you need to learn. Getting a good estimate of how much you can learn is also good.
>vulkan isnt that bad, its just tedious.
Yeah that's what I said. As a graphics API it's pretty bad though. It's more of a graphics card API than a graphics API. Being convenient was never the intent obviously, so it'd be difficult to call it bad because it doesn't fit what you might want out of it.

Then how should I ideally get past this? I thought I had hit a good solution, but alas, I'm back to the drawing board.

what is the "evil else"?

>average salary
Nice. Didn't even do a median. That's how you know they're wankers.

why not yes = ['y', 'yes', 'ya']
if pepe in yes

?

HOLY FUCK

>use this web course and make $105k a year!
seems legit

Tbqh I'm thinking of getting into JS and webdev just for fun, but (from facebook.github.io/react/):
handleSubmit(e) {
e.preventDefault();
var newItem = {
text: this.state.text,
id: Date.now()
};
if(this.state.text==""){
return //avoids inputting empty todos.
}
this.setState((prevState) => ({
items: prevState.items.concat(newItem),
text: ''
}));
}

This just looks awful. No fun.
>}));
This kind of shit would annoy me to no end.

If you're using python 2 import division from future

>>}));
>This kind of shit would annoy me to no end.
but lisp is beautiful and perfect, right?

in c++17 you can use std::launder(this) from to avoid it getting optimized out.
though your not supposed to use it for that. you can write your own version easily if you cant use c++17 too.


another way is described in the first few chapters of this.
dataorienteddesign.com/dodmain/

basically instead of putting nullable effects in your objects,
have a container of struct {object*, effect*}; which you can safely iterate over without checking nulls.
or something like that.

std::launder is easier though if you dont want to change too much though

>}
youre going to awaken them

>but lisp is beautiful and perfect, right?
No lisp is awful to read too.

What does it imply when a function is deprectated? I understand the idea of "don't use this". But what's the general process here that library authors apply?
Deleted next major revision? What can I expect usually.

I depends on the library.

Yeah. I understand. But I'm asking for someone experienced to give their input.

test

You already seem to have the right idea, though.
It depends on what the libraries goals for backwards compatibility are.
You may have a library which uses semantic versioning, and all functions will be kept until at least the next major version.
You may also have libraries that ALWAYS want to be backwards compatible (e.g. some standard libraries), and will never remove a function; they'll only tell people to stop using it.

>What can I expect usually.
that you shouldnt rely on it being there when you update the library.
though it depends on the library,
some libraries keep depreciated stuff around forever, some remove them as soon as possible, and others inbetween.

from semver.org
>How should I handle deprecating functionality?

>Deprecating existing functionality is a normal part of software development and is often required to make forward progress. When you deprecate part of your public API, you should do two things: (1) update your documentation to let users know about the change, (2) issue a new minor release with the deprecation in place. Before you completely remove the functionality in a new major release there should be at least one minor release that contains the deprecation so that users can smoothly transition to the new API.

desu don't understand this
the golang GC is trash and rust is roughly the same speed as C++

Thanks. That's kinda what I was looking for.

LLVM is fucking sexy

Make sure you add .lower() to the input, or else IGNORECASE on the regex. I can break your script by entering a capital Y

This is Ruby. Can someone explain to me what this is doing? I would specifically like to know if there is an array of strings being stored and what the variable name for it is.
File.open("test.txt", "r") do |f|
f.readlines.each { |line| puts line }
end

here is the Haskell equivalent if that helps

readFile "test.txt" >>= mapM_ putStr . lines

looks like its just printing each line.

oh, it should be (putStrLn) if (puts) is line terminated

Alright thanks, I thought there was an array somewhere here but I think it's just readlines that returns an array of all the strings read.

>when I want to print arguments in succession I must explicitly specify end="", sep="" in Python 3
Why is this allowed?

Do I just throw the error code returned by a function like:
int rv = foo();
if (!rv)
throw rv;

Or do I just do:
throw foo();


New to C++ pls lend assistance.

Why the fuck are you throwing integers?

You will always throw in the latter example. Still, you shouldn't throw error codes. If you need to use exceptions its better to make you own exception class to allow catching by exception types. Error codes are usually returned from functions.

What should I throw?

Longtime sepples faggot here. What's a good book on pyt*on?

Nothing. Both exceptions and C++ were mistakes.

dereference pointer
dereference address of pointer
address of dereference of pointer
dereference of dereference of pointer
dereference of dereference of pointer plus 3 (if it's another address ie ptr is ***something then 3 bytes after the final pointee)
dereference of dereference of pointer again
dereference of pointer (if ptr is ** or more indirected 3 bytes after the address pointed to by ptr*0
take ptr, add 3, dereference this address, add 3 bytes to the result, then dereference that as an address
erally, it all makes sense when you look at it logically

throw isn't valid C, if you have to write C++ you should always strive to write C code

can anyone hook me up with some junior level work with blockchain?

He's just starting and you're already trying to get him into your sect.

But you are kind of right, I feel you have to learn C before C++, otherwise half of sepple's features would seem like magic and not something you can reason about.

>with blockchain
What do you want to do?

So what is actually happening when you do throw foo()? is it throwing the return value? And if that's the case won't it throw regardless of whether foo failed or not?

write a compiler

write smart contracts, perhaps trading software?

Work on an actual blockchain would be brilliant but that requires a lot of knowledge and experience.

More than willing to learn but I need food on the table stat.

char *temp = (char*)malloc(sizeof(char)*BUFFER_SIZE)

Why is this bad practice?

>smart contracts
they're quite easy to write, the thing is that any bugs will fuck shit up so you have to be careful
>trading software
extremely hard to write, any fuckups will be even worse than with smart contracts since you'll actively lose money not just get it vulnerable
>Work on an actual blockchain would be brilliant but that requires a lot of knowledge and experience.
nah you can contribute to your latest meme currency, you don't have to come up with a brand new algorithm or anything just do some optimization work or write unit tests or whatever
>I need food on the table stat.
Isn't it better to just learn "regular" programming then?

So GCC is the fastest language?