/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

pastebin.com/brn9DhTF
en.wikipedia.org/wiki/Regular_language
twitter.com/NSFWRedditImage

First for D

I don't care about the anime thing but you could variate more the op pics. it's always the same 2 books

Great OP image.

First for node.js Sisyphean callback hell.

I can't in good conscience recommend other programming books because 99% of them are trashy bloated reference texts written for college classrooms.
They're basically cash cows for their publishers because they make a new one literally every school year.

I'm learning about neural networks now. They seem really simple. The hard part is backpropagation and getting the thousands of neuron's weights exactly adjusted to give you the desired output.

How do genetic algorithms work? Backpropagation is gradient descent complicated calculus stuff but wouldn't a genetic algorithm just be adjusting the weights randomly over thousands of simulations, killing off the nets the weren't performing right? Sounds dead simple.

>they make a new one literally every school year.
that's because new stuff comes out every year, while c is an outdated language lost in the 50s

Would be totally inefficient.
Backpropagation with gradient decent is dead simple. It's just the chain rule.

*1990

A language isn't supposed to receive yearly updates, you standardize it once and expect it to be supported on all platforms without ever worrying if all your users will be able to support X feature from 3 releases ago.

Look at python, they're still supporting versions 2 AND 3 simultaneously because nobody wants to switch and they're mutually incompatible.

ah really? I only took up to calculus 1 but I'll try to brush up on that and understand it. either way I'm going to try and get some fun stuff working using a premade neural net library.

Not thanks for using Himegoto image

You do realize that C was updated in 1995, again in 1999 and then again in 2011, right?

I can't in good conscience recommend K&R C either because it does not teach defensive coding practices, which is pretty fucking vital if you are writing C in TYOOL 2016.

It's a really neat historical artifact, well worth the purchase once you are actually familiar with the language, but if you write code like the K&R examples in practice you shouldn't be touching GCC with a ten foot pole.

Name ONE (1) useful feature that came with any of the C standard revisions.

Designated initializers.

Those weren't even really updates.
They simply standardized the non-standard GNU extensions that everyone came to enjoy from GNU C.

So what you're saying is that C received yearly updates then?

stdint.h

Those aren't updates, they're compiler extensions.

You can choose to ignore them and write in strict -std=c90 -Werror -pedantic mode if you so please.

Somebody updates GCC.

>task: rewrite this block of code in a different/better way
if condition {
execute_a()
execute_b()
} else {
execute_c()
execute_a()
execute_b()
}

// Double slash comments

Single-line comments and declaration of variables inside conditionals

You may be retarded if you can't do this.

Better:
if (!condition)
execute_c();
execute_b();
execute_a();


Different:
switch (condition) {
case 0:
execute_c();
default:
execute_b();
execute_a();
}

If ¡condition {
Execute _c();
}
Exec_a();
Exec_b();

Phone posting and learning C.

Any Javascript (plain Javascript) books or courses that teach how Javascript works itself and with the DOM?

Looking for something that assumes knowledge of programming, not intro to programming that uses Javascript.

unsigned i, iters = (cond) ? 2 : 3;
void (*exec[3])() = {
execute_a, execute_b, execute_c
};
for (i = 0; i < iters; i++)
exec[i]();

Best way I could think to do it :/

void (*func_ptr[3]) = {execute_a, execute_b, execute_c}

int i;
for(i = 0; i < 2; i++){
if( condition && i == 0)
(*func_ptr[i])();
if( condition && i == 1)
(*func_ptr[i])();
if(!condition && i == 2)
(*func_ptr[i])();
}

>teach how Javascript works itself and with the DOM?
I'm not really sure 100% what you mean by this to be honest, but Javascript: The Good Parts is a fairly good intro if you already know how to program and its only like 100 pages or something.

What happens if the condition is false?

sequence_ $ drop (fromEnum condition) [ execute_c, execute_a, execute_b ]

Oh you're right mate terribly sorry, I also forgot a semicolon. I believe this should work.

void (*func_ptr[3]) = {execute_a, execute_b, execute_c};

int i;
for(i = 0; i < 2; i++){
if((condition || !condition) && i == 0)
(*func_ptr[i])();
if((condition || !condition) && i == 1)
(*func_ptr[i])();
if(!condition && i == 2)
(*func_ptr[i])();
}

I'm a reporter with Sup Forums's official nightly news station.

Why do you guys come to /dpt/? To socialize? To learn?

The most important task that can be done, 4NN.
Procrastinating on writing code.

Your function pointer array declaration requires an argument list.

Fuck you and your lies

>condition || !condition
this will always be true

Not if there's a fault in the universe where true equals false for a moment. Gotta check for that.

Only in classical logic

In what logic is it not true? It's true in fuzzy logic as well: x + 1-x === 1.

made a game called browncoats

pastebin.com/brn9DhTF

Shit, sorry guys. Fixed those things, also thought of an additional optimization. Feeling good about this one.

void (*func_ptr[3])() = {execute_a, execute_b, execute_c};

int i;
for(i = 0; i < 2; i++){
if(true && i == 0){
(*func_ptr[i])();
}
if(true && i == 1){
(*func_ptr[i])();
if(condition){
goto EXIT;
}
}
if(!condition && i == 2)
(*func_ptr[i])();
}
EXIT: //continue...

> +

Why do you need several if conditionals?

Just do

Yeah, I'm dumb.

I convinced my coworker to use a goto once. I'm still convinced that it would have been more efficient to use a goto, but I used a language trick to get around it since a goto made him squeamish.

shouldn't it be

unsigned i, iters = (cond) ? 1 : 0;
void (*exec[3])() = {
execute_c, execute_a, execute_b
};
for (i = iters; i < 3; i++)
exec[i]();

But that's the same thing. It still doesn't run execute_c() if cond is false.

You might as well write it
unsigned i, iters = !!cond;

>What are you working on, Sup Forums?

Learning regular expressions to increase my power level.

Is this a good idea?

yeah but according to execute_c() should be executed before execute_a() and execute_b().
In execute_c() comes after.

It's never a bad idea to learn something new in your field, user. Especially something as relevant as regex.

If your output is completely dependent on the execution order of your instructions, your code is shit.

I'm starting to think that there isn't a better way to rewrite it, since everyone seems to fail on the first try.

>it does not teach defensive coding practices,
wut

Always, but read about the "regular language" too for some background.

en.wikipedia.org/wiki/Regular_language

She seems to think that initializing your variables and doing bounds checking is difficult.

but that's how non-parallel computing works.

Books are free, user. Read them and find out.

What are possibilities of programming on the non-Android phone?
Please keep answers relevant to the question.

I guess iphone apps make more money since people who have iphone usually aren't poorfags

Allocating a 3 dimensional array dynamically in C.
#define SIZE 1024
int i, j;
int ***arr = (int ***) malloc(sizeof(int **) * SIZE);
for (i = 0; i < SIZE; i++)
arr[i] = (int **) malloc(sizeof(int *) * SIZE);
for (i = 0; i < SIZE; i++)
for (j = 0; j < SIZE; j++)
arr[i][j] = (int *) malloc(sizeof(int) * SIZE);

trying out TempleOS

>only three stars
Weak m8

r8 my waifu

Sorry for the retarded question, but what's the proper way to do this?
if(a[i] == b[0] || b[1] || b[2] ...){
do something
}

Just doing b[0] works but adding anything else breaks it. I'm using || wrong right?

Allocating a 6 dimensional array dynamically in C.
#define SIZE 1024
unsigned i, j, k, l, m;
int ******arr = (int ******) malloc(sizeof(int *****) * SIZE);
for (i = 0; i < SIZE; i++)
arr[i] = (int *****) malloc(sizeof(int ****) * SIZE);
for (i = 0; i < SIZE; i++)
for (j = 0; j < SIZE; j++)
arr[i][j] = (int ****) malloc(sizeof(int ***) * SIZE);
for (i = 0; i < SIZE; i++)
for (j = 0; j < SIZE; j++)
for (k = 0; k < SIZE; k++)
arr[i][j][k] = (int ***) malloc(sizeof(int **) * SIZE);
for (i = 0; i < SIZE; i++)
for (j = 0; j < SIZE; j++)
for (k = 0; k < SIZE; k++)
for (l = 0; l < SIZE; l++)
arr[i][j][k][l] = (int **) malloc(sizeof(int *) * SIZE);
for (i = 0; i < SIZE; i++)
for (j = 0; j < SIZE; j++)
for (k = 0; k < SIZE; k++)
for (l = 0; l < SIZE; l++)
for (m = 0; m < SIZE; m++)
arr[i][j][k][l][m] = (int *) malloc(sizeof(int) * SIZE);

>malloc
>not calloc

a[i] == b[0] || a[i] == b[1] || ...

...

Thanks.
Is there a better/shorter way of doing it if b[] contains 6 elements?

a switch may be good

switch(a[i]) {
case b[0]:
case b[1]:
case b[2]:
...
// do something
break;
}

Go back to complaining about Python 3, Zed.

You only need one for

foreach(j; 0..6) // or a for loop if your language sucks and doesn't have a foreach
{
if(a[i] == b[j])
{
//do thing
break;
}
}

>allocating 2**(10*6) bytes of memory

Name 30 more.

how do you do that cody thingy?

that would "do thing" more than once

>break;

Just die already.

You're the only trip fag I don't hate

>break
I'm a retard

>a[i] == b[j]
B)

Nice trips, my guy.

is there any practical difference between break/continue and goto?

Cleaner, easier to use, don't have to set extra labels to use them

>an hour wasted not realising some prick thought "near" and "far" were good macro names
>finally fix bugs
>compiler out of heap space

FUCK YOU C++
I HATE YOU
YOU ARE SHIT

> Macros
Not even once

>hahaha macros are the problem
Oh yeah, let me just #inc
oh wait

You should see a doctor. I think you've had a stroke.

visual studio is nice because it shows a chart of memory used x time.

... no, it was the COMPILER that ran out of space.
because apparently C++ allows types and namespaces to have the same name, but only if it then results in a compiler error

programming languages final in 8 hours. does anybody have some good practice programs or exercises to do in Scheme, Haskell, and Prolog?

a program that calculates the factorial of a number

> Programming final
I wish for simpler times

can do that tail and non-tail recursive, looking for something more challenging

but thanks!

Day 8 of AoC doesn't even seem fun, it's just parsing commands and shifting arrays by one.

Given the amount of shit C codebases out there, and the number of vulnerabilities out there caused by said codebases, it apparently is something a lot of programmers skip out on.

Lord knows we don't need more OpenSSL's in the wild.

Could you please leave?
You clearly get all your knowledge of C from sensationalist websites.