/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1550741470164.jpg (1024x576, 99K)

Other urls found in this thread:

elixir.bootlin.com/linux/latest/source/include/linux/list.h
youtube.com/watch?v=E4RarTAZ2AY
twitter.com/AnonBabble

Yuno is not programming related

Attached: 1549310003146.png (1280x720, 891K)

Yuno is anime.
Anime is programming related.
Therefore, Yuno is programming related.
Q.E.D.

Attached: 1550609477481.jpg (201x450, 24K)

Isn't user the programmer's wife programming related?

Attached: 1548937499032.gif (384x288, 46K)

Yuno is just another lisp.

Attached: 1550439840053.gif (351x329, 169K)

There's no face obstruction. Whether the larger or smaller face is closer to the viewer it will look the exact same, since the object is "transparent" combined with the fact that I'm using an orthographic projection. Do you think that might be what's causing the rotation to seem off?

>Do you think that might be what's causing the rotation to seem off?
Yes, the way you're drawing it certainly could cause that.

It's better than that dork who insists on making non-anime /dpt/s.

Attached: 1549138733472.jpg (500x380, 37K)

Reminder that if you're not programming in C++26 you're not programming, you're just scripting/playing with lego.

>implying there's something wrong with playing with lego

Can someone explain to me what functional programming is?

So far I have only learned about object oriented programming.

Python programmer spotted.

Do you know how does math functions work?
FP works similar.

Correct.

Attached: images.jpg (225x224, 7K)

Yeah. So, to use a C++ example, if one were using templates, that would be functional programming? It's basically circumventing the compiler in that sense

basically it's about higher order functions, and relatively pure functions

>Templates are circumventing the compiler
No.

>code segfaults when compiled with -O1 and -O2 but not -O3 or O0

what the

> -O3
Compiler can detect shit and optimize it
> -O0
Compiler cannot detect any shit and optimize it.

undefined behavior, optimizations change the actual behavior.

-Wall -Wextra and valgrind

Yeah I'm digging through it.

Point was I would expect anything broken by -O1 or -O2 to break under -O3 too.

It's probably something stupid like O1 and O2 listen to you and don't optimize a loop away, but O3 unrolls it and you don't hit the same race condition or something. I know O3 does a lot of things, like removes things if they're not used, so it's possible you're accessing something you don't intend to in 1 or 2, but in 3, the offender is optimized out, and you're mis-accessing data which doesn't corrupt your program.

Why is C so unreadable? The difference between (*var)++ and *var++ is catastrophic, but hardly discernible.

Attached: Screenshot_2019-02-22_17-21-08.png (609x210, 32K)

just be thankful that it's not one of those bugs that disappear when you use a debugger.

Don't write shit code that that, then.
I'm especially bothered that htable appears to be a typedef for a pointer to a pointer.

how about this instead

add(var*, 1);

syntax error

>I'm especially bothered that htable appears to be a typedef for a pointer to a pointer.
What's wrong with that?

Typedefs are shit most of the time, and just hide important type information from you.
That's especially true for pointer types.

Ah yes, I’ve got it! A syntax for an extremely concise language that is basically Assembly macros and allows for pretentious obtuse one-liners. This is why Jesus invented the computer.
factorial n i1=??>n0(*i n-n1)i

>??>
Is that supposed to be a trigraph or something similarly retarded?

Yeah, but the codebase doesn't need to be littered with references to the hash table structure, that's all internal.

>??
while
> >n0
n is greater than zero
>(*i n-n1)
do stuff in parentheses

What's wrong with passing an opaque struct hash_table * around? It's how literally everything else works, and information hiding from yourself is pretty dumb.

What language would they program in?

Attached: potatos.png (1920x1080, 1.36M)

>n is greater than zero
How the hell is the lexer for that going to work? Or do you not allow digits in identifiers?

I’m not allowing digits in identifiers. This way one-liners are shorter and therefore more pretentious.

Probably something imaginary like they are.

Gofags what's up with this syntax:
hash.(*object.Hash)

Have two arrays of numbers. Have to add one number from array one, to another number from array two such that they come closest to a target.

How do I do this?

malbolge for the despair, fish for fish.

forgot my image

Attached: 1550755016868.jpg (750x717, 65K)

You have to write it in Assembly or it won’t work.

nim!

>such that they come closest to a target
what? these questions are usually easier to answer if you post a sample input/output and what you've tried so far.

>such that they come closest to a target.
What does this even mean

I keep having to fix bugs in the assignments my Data Structures teacher posts that make them unsolvable, this has happened like 10 times this semester

That function shouldn't be inlined dude

not him but I'm assuming that's from a header file. although completely useless and pretty much ignored by the compiler, for some reason it's common for functions in headers to be marked static inline rather than just static.

uhh you guys are pretty dumb for programmers

does someone have an actual reponse to my question
NEXT

>The dumb ESL nigger screams out in pain as he strikes you

>tfw you get stuck in a problem and get severely frustrated
>tfw you love programming but you're dumb
If I persevere I will make it through, right?

Attached: 1544216130543.png (300x200, 137K)

>If I persevere I will make it through, right?
that depends on you, how's your japanese?

Why would it be ignored by the compiler, how does it know it came from a header when the preprocessor includes it in the source file?

>how does it know it came from a header when the preprocessor includes it in the source file?
It doesn't matter where it came from, modern compilers pretty much ignore the inline keyword and inline things as they see fit. There's ways force inlining, like __attribute__((always_inline)) but that's not the inline keyword.
I think static inline in headers is pretty much a style choice, it basically says to the programmer: this would be a macro but making it function adds some type checks.

Stop worrying about whether you can solve the problem now and instead take this opportunity to learn.

here's an example, you could remove every single inline keyword in this file and it would most likely compile to the exact same object code.
elixir.bootlin.com/linux/latest/source/include/linux/list.h

:)

Attached: ballin 2.webm (1024x748, 1.18M)

That's petty gay.

Not programming, fuck off.

Learning Elixir boys.

thanks.

Elixir is just Erlang without the hello joe.

Attached: hello joe.jpg (480x360, 17K)

Will do

Attached: 1544232533783.png (319x158, 107K)

.

Attached: 1550875139839.png (1200x1400, 284K)

Based

>Not unregistered hypercam
You need to step up your shitposting.

(define (make-car)
(match-lambda*
(('drive) (display #\-))
(('honk) (display #\alarm))))

(let ((car (make-car)))
(car 'drive)
(car 'drive)
(car 'honk)
(newline))

lispman strikes again

I'll keep that in mind.

Where should a retard like me with no head-math skills start on the journey to into programming?

I struggle to add double digits in my head but i understand the theory of calculus and can visualize cartesian planes in my head.

>self-taught meme
how true is this? can you get a GOOD job as a self-taught programmer or are you doomed to be a perma-codemonkey making 40k a year

>honking only once

Attached: 78.png (300x100, 14K)

Start with C and Python simultaneously. It ain't that hard.

>Will do
That's the spirit. The journey of a thousand miles begins with a single step.

What's the problem? What language are you tackling it with?

Attached: Legacy is the definition of human purpose and meaning.jpg (770x1024, 117K)

Which book should i read?

C

I just got a little demotivated because there were some exercises in the book I'm reading that I couldn't do right off the bat and I assume the book (C programming a modern approach) expects you to be able to complete them all before moving on to the next chapter

Attached: warrior.jpg (482x750, 133K)

im trying to average a single row of this array in my switch function's case 't' but im doing something wrong. can someone explain how this is fucked up? heres the entire code so far
#include

int main(void)
{
char x = ' ';
int count;
int j, i;
double studentnumber, homework, quizzes, final, avg, sum;


printf("How many students are in the class?: ");
scanf("\n%d", &count);

double array[4][count];

do{

printf("\nA or a to add student info one student at a time\n");
printf("D or d to display student's info\n");
printf("T or t to display class average for homework\n");
printf("S or s to display class average for quizzes\n");
printf("B or b to display class average for final exams\n");
printf("W or w to display class average for student's final grade\n");
printf("Z or z to exit program\n");
scanf("\n%c", &x);

switch(x)
{

case 'a': case 'A':
for(j = 0; j < count; j++){
printf("Please enter student number:");
scanf("\n%lf", &studentnumber);
printf("Please enter homework grade:");
scanf("\n%lf", &homework);
printf("Please enter quizzes grade:");
scanf("\n%lf", &quizzes);
printf("Please enter final exam grade:");
scanf("\n%lf", &final);
array[0][j] = studentnumber;
array[1][j] = homework;
array[2][j] = quizzes;
array[3][j] = final;
}
break;

case 'd': case 'D':
printf("Please enter the desired student's number: ");
scanf("%lf", &studentnumber);
for(j = 0; j < count; j++){
if(array[0][j] == studentnumber){
printf("\nHomework grade: %.2f", array[1][j]);
printf("\nQuizzes grade: %.2f", array[2][j]);
printf("\nFinal exam grade: %.2f", array[3][j]);
printf("\nFinal average: %.2f", array[1][j] * 0.5 + array[2][j] * 0.1 + array[3][j] * 0.4);}}
break;

case 'T': case 't':
sum = 0;
for(j = 0; j < count; j++){
sum += array[1][j];}
sum = sum / count;
printf("%.2f", &sum);
break;

case 'Z': case 'z':
printf("goodbye");
return 0;

}

}while(1);

return 0;
}[\code]

I did it. The compiler exists. The world is fucked now. Behold Smugscript (which isn't a scripting language)
fact n i1=??>n1(*i n-n1)i

fact:
mov rbx, 1
cmp rax, 1
jle exit1
loop0:
imul rbx, rax
sub rax, 1
cmp rax, 1
jg loop0
exit1:
mov rax, rbx

Python Crash Course for a quick introduction to python and K. N.King's C Programming (ignore some of the C99 stuff).

Try to tackle the problem, and if you get stuck then keep the point you got stuck on in mind (or on paper) and read on. If no solution is provided and after re-tackling the problem with more knowledge you can't find a solution, then feel free to ask in /dpt/.

You should try to solve a problem when you encounter it, but don't think you have to build a bridge before you know what a brick is. Don't be ashamed to read ahead if you get stuck, learning is all about asking questions and finding answers, so feel free to do that.

Out of curiosity, what is the specific exercise in question?

Post source

C and C++ have a lot of similarities, so could i get away with learning both at once? Most reports show that C++ has higher job offers than C.

Wrote yourself a compiler?

Designing a DSL for 3d modelling

I have no attention span

>double array[4][count];

There's at least a big problem.

does case D work?

yes
also i think its noteworthy to mention that if you use case d before you use case t, case t spits out whatever the final average is.
i just learned arrays like two days ago, is this wrong because you just simply cant declare an array with a variable or something?

I'd say switch over to C++ after you've got a hang of dynamic allocation and pointer arithmetic with C and have a general idea of how classes work with python.

Nice circles. I'm giving it a 10/10 for consistent roundness.

youtube.com/watch?v=E4RarTAZ2AY

I wrote it in like 15 minutes and it can currently only compile one line programs. I promise I'll put it in a pastebin and post it here eventually.
>Wrote yourself a compiler?
I've written many, mostly just toys and school projects. But this one's special because it actually serves a specific purpose which is to be a concise language that compiles almost symbol for symbol into Assembly, letting me write Assembly as a human at a much faster pace.
program length: 26
assembly length: 159
ratio: 16%

Basically brute forced my way into a vector of circles for collision detection. Wish I could try something more efficient.

Does it support both manual memory allocation and monads?

These were the very first exercises that I couldn't wrap my head around so I just skipped them and went to the next chapter but the next chapter's exercises were even harder and that's where I lost motivation

Attached: darn.png (370x205, 37K)

The frame rate looks fine to me.

It will.

scheme is actually pretty elegant in some ways

Attached: 1549310148953.png (1920x1080, 2.63M)

What about s-expressions?

>is this wrong because you just simply cant declare an array with a variable or something?

Essentially. The amount of memory that would be needed isn't known at compile time (it depends on how big count is). You can pre-allocate space and check to make sure the amount requested doesn't exceed that, or you can allocate enough memory once you know how much you'll need.