/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1527458398673.jpg (1280x720, 408K)

Other urls found in this thread:

strawpoll.com/e85bx7zw
twitter.com/SFWRedditVideos

First for Haskell and the direct link between programming and depression

Attached: dpt.jpg (575x69, 14K)

2nd for what should I read next to improve my c++?

Attached: 1486596925978.jpg (637x579, 47K)

>what should I read next to improve my C++
Dante's Inferno to get a good grip of what you're in for

such divine comedy, user

n-th for C

5th for haskell tiddie monsters

Attached: 1525395445547.png (850x1200, 1.18M)

0th for C

1st for the first element of an array in C

a) Function RandomShit(int a ){
code here
}

b) RandomShit = a=>{code here}

So exactly why are Lambdas so fucking amazing, is it a meme? Its the same shit

Lambdas are nothing without Higher Order Functions

lets you pass functions as arguments without having to declare it

...and

Capture variables from the surrounding scope

>future
>promise
the hell am I reading, bjarne

Attached: 1536166090501.png (1032x1394, 759K)

array.map(x => x * x + x)

vs
function IWillNeverUseThisAgain(int a) {
return a * a + a;
};
array.map(IWillNeverUseThisAgain)

Can't spell Chad without C

>So exactly why are Lambdas so fucking amazing, is it a meme? Its the same shit
Lambda captures can contain state without having to take it as an arg.

Added support for slices in my programming language. Also initially posted in sqt because it pops up in the catalog when you search for dpt.

Attached: slice.png (328x306, 16K)

#include
#include
#include

int main(void)
{
int n;
char bebytes[sizeof(n)];
char lebytes[sizeof(n)];
size_t i;
n = 0;
for (i = 0; i < sizeof(n); i++) {
lebytes[i] = i + 1;
bebytes[sizeof(n) - i - 1] = i + 1;
n *= 256;
n += 4 - i;
}
if (n == *(int *)lebytes) {
fputs("little endian\n", stdout);
} else if (n == *(int *)bebytes) {
fputs("big endian\n", stdout);
} else {
fputs("unknown architecture\n", stderr);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

What is it? A clone of GNU Octave?

Why do bad programmers always write endless if-elseif chains?
Are they taught never to use switch-case?

There is no problems with elseif chains.

It's slow

public static boolean p(int n){
int s = Math.floor(Math.sqrt(n));
if (s

No. A good compiler know how to handle those.

So 1 is prime?

Why do bad programmers always feel the need to bring up switch statements the second they see an if/else chain longer than 2 or 3 conditions? They're not necessarily interchangeable.

JavaScript rocks... don't forget that! Hmpf

Attached: 226de60a54ad522581fe79abf498426b.jpg (685x899, 85K)

No, just an interpreted language inspired by Python and Lua that I'm working on, but apparently GNU Octave also supports similar slice syntax.

And especially when the problem isn't the O(n) worst case time vs O(1), but rather the core logic not needing conditionals and boilerplate at all.

#ifdef BIG_ENDIAN
...
#else
...
#endif


$ gcc src.c -o bin -DBIG_ENDIAN


No need to make it more complicated

const arr = [
{"items": [{}, {}, {}]},
{"items": [{}, {}, {}]}
]

const foo = arr.reduce((a,v) => [...a, ...v.items],[])

See

Oh just duct taping an MSP 430 on the wall and leaving it with this message:
sevenSegInit();
SevenSeg_SetText("pls rember that wen u feel scare or frigten never forget ttimes wen u feeled happy | wen day is dark alway rember happy day");

?

what did he mean by this

Attached: 33333333.png (727x365, 16K)

It's concise syntax for the same thing, yes. Like the other user said, the real benefit is when you mix it with higher-order functions.

That's a closure. Anonymous functions usually do the same thing.

Don't have time for retard who failed to understand what a code does and post a code that does something else.

>retard who failed to understand what a code does
so what does it do and why is that user wrong?

Why do bad programmers always assume their trivial syntax micro-optimizations are a huge important thing?
don't they know how compilers work?

In the previous thread there was a swedish "girl" with 160 long if then else where every single condition was if(text =="some number"), that's what I was referring to

Don't have time to explain. I have time for trolling, not for explaining trivial things to baka.

How many years have you been programming /dpt/?
strawpoll.com/e85bx7zw

Ugly
arr.flatMap(x => x.items)

>Strongly typed languages are good!
Why do people always say this?

It's such a pain in the ass, when you try to write str = '#' + str; and you get "Whoops dunno how to convert char to string xD"
Even more annoying when it uses some annoying memetype like "Thickness" that takes one int as a ctor, but no, Border.setOutline(5) is incomprehensible, unsafe, unclean clde, you have to write fucking Border.setOutline(new Thickness(5)) or some shit, because god forbid you didn't have to google up the documentation for every menial fucking bullshit thing you want to do.
Because herp a derp, we are too cultured and hip to use C++!

Just today I wanted to do this in C#, it detects up to which letter it needs to use for a custom number-base system, aka for 16 it'd be F
So I write "limit = (char)(num - 11) + 'A'"
Oops operator + is not defined for char and int! So what's the correct syntax?
limit =(char)(num - 11 + 'A')
How does this even make sense?

Attached: 1497370418079.jpg (171x189, 24K)

>It's such a pain in the ass, when you try to write str = '#' + str;
Name one languge in which string operations don't suck ass

I recall that. A switch statement would really not be an improvement, aside from (possibly) slightly better performance. It was just mapping integer IDs to strings, which would be better handled using a dictionary or array populated using a text file (to aid in translation). Or, if translations aren't needed, just skip the ID and use the string directly. Plus, instead of magic numbers, at least use an enum.

>Don't have time to explain. I have time for trolling, not for explaining trivial things to baka.
then why post in the first place?

fuck outta here

>It's such a pain in the ass, when you try to write str = '#' + str; and you get "Whoops dunno how to convert char to string xD"
That's a dumb example. Just write "#" + str. + for string concatenation is horrible anyway, + should be commutative.
>Even more annoying when it uses some annoying memetype like "Thickness" that takes one int as a ctor, but no, Border.setOutline(5) is incomprehensible, unsafe, unclean clde, you have to write fucking Border.setOutline(new Thickness(5)) or some shit, because god forbid you didn't have to google up the documentation for every menial fucking bullshit thing you want to do.
It would make sense if you had one constructor for pixels and another for points.

Not for double free, it's for dangling pointer. If you null the pointer and then try to dereference it, you get a segfault.
You can't write it with only a macro or only a function while avoiding evaluating the expression twice. Or maybe you can, actually.

JavaScript unironically.

You are right, I didn't think about that
Still, in an ideal scenario if there is no clash it should just compile, and only give an error if it's not obvious what class to create

>no printf
Try again.

C
Perl

>printing to console in javascript
Who does this?

>Even more annoying when it uses some annoying memetype like "Thickness" that takes one int as a ctor, but no, Border.setOutline(5) is incomprehensible, unsafe, unclean clde, you have to write fucking Border.setOutline(new Thickness(5)) or some shit, because god forbid you didn't have to google up the documentation for every menial fucking bullshit thing you want to do.
>actually wishing for implicit object creation

I'd agree with Perl but not C

>console.log

Let me rephrase:
>no sprintf
>no String.format

C has really nice string tooling, you just got to know how to use it.

Yikes

I would like to create a program to filter in real time advertising from a video stream. I would like it to check if a sequence of video is already in a database and mute it if it's an ad. I literally want to kill advertising on TV. Would it be possible to create such a program? Would it be easier to use audio instead of video? Also are there libraries for this kind of task? Could I do this in C or I should learn C++/Rust for this program? Could this be done relatively efficiently on a small computer like a raspberry pi or this kind of task is too hard for real time? (small delay is fine though)

I'm pretty new to go.
I want to abort execution of a function as soon as another instance of that function is called. Is there an obvious more elegant/ better solution than this?

func someFunction(abort chan bool) {
select {
case

Would it be beneficial to learn programming for a regular IT job, or just learn how to do scripts?

So this is the power of Go

t. stupider than pajeet

scripting is just a small subset of programming

> num
23
> num +1
231

Whoops that's not what I meant to do xD

>Computer programming is the process of designing and building an executable computer program for accomplishing a specific computing task.
Look like you are already a programmer as said.
Of course you can learn many advanced things that will make you a better scripter.

>I literally want to kill advertising on TV
there are much better ways to do this on TV
IIRC there is some kind of sentinel value sent as part of the video signal to mark the beginning and end of the commercial break
so you could simply watch for that. there are DVRs that already do such a thing, and IIRC the company making them was sued by some cable company over it so it must work pretty well

wanna stop blog posting about babys first program. do you seriously need validation for minuscule thing you do.

your poor english could benefit from typechecking

dynamic typed languages are just so convenient, I never have to worry about those silly "compiler warnings" telling me that the code i've written is "probably a bug" because i'm using integer functions on a string!
it's so easy!

Why don't more people do web development in C++?

The term you're looking for is "weakly typed".

no such thing as weakly typed.
it's either typed or not.

You can't tell if a pointer is dangling unless you're working in a language that can't access pointers.

fuck C++
fuck cmake
fuck barney soupysoup
fuck the standard committee
fuck everything about this shit language

its time for the world to move on to greater things
it will take time but we must take action and stop using this garbage
life is too short for C++ my programming brothers, please value your time more

Yeah I heard about that thing but it seems way too easy for them to stop sending this signal right?

well looks like that 3ds devkit works with c++, gonna test it more thoroughly tomorrow.
gonna be fun
goodnight

Attached: 1424857990338.png (426x364, 10K)

No
Javascript - weak, dynamic
Python - strong, dynamic
C++ - weak, static
Java - strong, static

They already need to send it for other reasons AFAIK -- e.g. the cable-company-provided DVR might refuse to skip forwards while in a commercial section

If they totally break it then you'd probably have an easier time just setting up a media center to play pirated files compared to whatever real-time video interpretation shit you were thinking of

>strong v.s. weak
nigga, if you're going to make a spectrum, they're all on the same side. the difference is minor

what language has the best static type system and why is it haskell

Thumbnail makes it look like a comfy 60% mechh keeb with random pastel buttons
Highly dissapoint

Attached: 1555618936182s.jpg (125x106, 3K)

>doesn't even have dependent types

because it doesn't have d*pendent types

>doesn't have linear types

no path types

>no sessions types
>best static type system
pick one

unfortunately it lacks security types

Linearly ordered effectful gradual pi session region types will save haskell

Is this niggerlicious or divine intellect?
function tryme()
{
console.log(`${arguments[0]} ${arguments[1]}`);
}

tryme(100, 200);
tryme("Hello", "World");

Divine intellect is being able to type the following as-is to print it out:
"hello world";

Do you really have to ask?

Attached: 07831356a4d57b49452a559ed6a64cf9.jpg (847x712, 360K)

yes

>p(s);
what's this supposed to do? aside from wasting processor time

no

99th for fuck anime.