/dpt/ - Daily Programming Thread

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

Attached: K&R himegoto waifux2.png (1000x1400, 1.31M)

Other urls found in this thread:

hackage.haskell.org/package/tardis-0.4.1.0/docs/Control-Monad-Tardis.html
docs.idris-lang.org/en/latest/st/state.html
twitter.com/SFWRedditGifs

None of the people who complain about C++ in these threads have written any noteworthy software.

Nobody in these threads has written any noteworthy software, especially me

Attached: 1554676134972.jpg (434x479, 44K)

nth for Nim!

Especially you

Attached: 1552401196799.jpg (1440x810, 392K)

>clips a signed integer to the range —128,127
>literally takes int8_t as an argument
Kek whoever wrote this is retarded

I'm working on internally screaming because I have a 300 level math test friday and I'm about to graduate and haven't even written my resume yet. Am I doomed to become a fat neet who pontificates about Lisp?

I'm trying to do more with programming. I know the syntax and enough to copy paste from stack over flow and link it together. But I have no formal training.

Could ya help an n'wah out and recommend some books on thinking like a programmer plz :^).

>if ((a+0x80u) & ~0xFF)
0x80u is 01000000 in binary
if a >= 11000000, then a+01000000 = 1 00000000
&~0xFF - if there are bits before the last 8 (and by ~0xff = and by 0xffffff00)
>return (a >> 31) ^ 0x7F
a gets the MSB of a (assuming, of course, that a is 32-bit)
xor with 0x7f (01111111)
if a == 0, a was positive, giving 127
if a == 1, a was negative, giving -128

>else return a
that condition didn't trigger, a was within range

It's retarded "clever" code though

return a > 127 ? 127 : a < -128 ? 128 : a;
This is as fast, don't ever fight the compiler

You are right, but C++ is still a shit language.

it returns int8_t, takes an int as an argument, who's the retard, huh?

no, it doesn't, are you blind?

Post 8 bucket string hashing algorithms.
int hash(char*s) {
char c;
int h=0,i=0;
while(c=s[++i])h^=c;
return h&7;
}

Attached: 1554686920616.png (434x521, 43K)

>need to install firefox because of some particularities about its extensions
>think that after all these years it's a good time to jump back to it
>right click tab
>absolute infested with useless garbage
>same thing for pretty much every other menu and feature
Jesus christ I'll code my shit as fast as I can so I never have to look at this again

Attached: Screenshot_22.png (299x327, 10K)

in C, can all pointers be accessed with array like syntax?
does ptr[i] mean "the value at (ptr+sizeof(i))"?

You have multiple add-ons installed.

My fault, I guess.

Attached: Screenshot_23.png (709x817, 21K)

>in C, can all pointers be accessed with array like syntax?
Yes.
a[i] is defined to be exactly equivalent with *(a + i). All array accesses are actually defined in terms of pointers.

As a fun side fact, you can reverse it, so: 5[ptr] is the same as ptr[5] since they're both ptr + (5 * sizeof(ptr)).

Do you actually comment the code you write for personal use?

That container stuff is also not enabled by default.

>sizeof(ptr)
That's not how pointer arithmetic works.

You obviously wouldn't write sizeof since that's inferred in pointer arithmetic, but that's what it boils down to in the context of explanation.

All I did was create an account to sync, install those addons and change a couple options about how tabs open (don't move to tab when opening link with middle click, for example)
But sure, if it makes you feel better I'm retarded and actively fucked up the browser just to complain on Jow Forums.

why wouldn't that be?
a int* (in my platform) has the size of 4 bytes.
so ptr[i] equals "the value at the address (ptr + 4 * i);

Stop presenting it like that's how the syntax works. Pointer arithmetic does not require you to baby the type sizes, and just deals with that shit for you.

Yes, extensively.
It rwally helps when you need to dig through this shit years later.

Which one? Downcasting signed numbers (or whatever the correct terminology is) is well defined, right?

Attached: Screenshot_2019-04-10_16-16-47.png (1187x391, 66K)

Yes, I use languages with strong and expressive type systems.

That's 128 buckets.
#define hash(s) strlen(s)&3

unsigned int hash(char* s)
{
unsigned int rc = 1;
while (*c)
rc *= *c++;
return rc & 3;
}

can i become good at coding (general stuff, native linux software, networking, none of that AI stuff) if i'm average at math?

Yes, as long as there is no overflow. Since there is no overflow in your function, only the first branch ever has to be evaluated.

Yes. I am shit at math and very good at programming.

>rc & 3
Yours is 4 buckets. Why are Ctards so bad at C?

Attached: 19B85A6B-DDBA-4495-9064-612F86F5B16F.png (317x451, 228K)

this image physically hurts me
name 1

either pieces of code are utter garbage as 1. they depend on implementation defined behavior 2. are unreadable

JavaScript rocks, don't you know?

Attached: 1549928956774.jpg (1440x1920, 197K)

Shit, my bad, I'm getting tired. I thought it was last N bits.
None of them do, unless you claim one's complement is relevant today. No implementation-defined behavior in either.

what happened to the old guy? you've been posting good images for a while js rocks dude

Rust, Haskell, the list goes on

>Rust
>expressive

Attached: 1548911174725.jpg (401x500, 32K)

If I'm reading it correctly, it's implementation defined, and can even raise a signal, but most implementations do something sane. C is goddamn awful, no wonder most people ignore the standard beyond UB

Attached: 1424866936726.jpg (375x281, 16K)

>dfw
go back to /lit/

you forgot
>rust
>good type system

Why is it so verbose to do a fucking api call on Java?

define "api call"

he said strong and expressive not good and expressive

In javascript i'd do something like this using axios package
axios.get("jsonplaceholder.typicode.com/todos/1")
.then((res) => {
console.log("Done");
}).catch(e => console.log(e);


but in Java it seems to be a mess to do a simple httprequest.

>Rust's type system
>strong

Because java assumes you are fucking retarded

what are you using to make an http request

The creator literally made it because his co-workers were fucking retards. Same deal with Go.

java is unbearable without apache and google dependencies.

Why are they called "for" loops?

try {
var stream = new URL("jsonplaceholder.typicode.com/todos/1").openStream();
System.out.println("Done");
}
catch(IOException e) {
System.out.println(e.getMessage());
}

depends on the language nerd

inherited from how mathematicians read.

>"""URL""" class to make HTTP requests
>having to deal with retarded Java streams and resource management for a simple GET
I know Java has an awful design but this shit looks like it was designed by little jeets.

Attached: 1554776165835.jpg (600x600, 106K)

Where can I get this "comiczin"?

i dont think you understand what good design is

They all call it for loops. Languages that dont use loops for iteration just use recursive lambdas

doesn't do the same thing and you forgot to close the stream.

>recursive lambda

Attached: 1525891708311.png (229x220, 6K)

>what good design is
Sun was too high on dotcom fumes
s = new Get("w/e").stream();

Me too, thanks

Working on a UI designer for my operating system. It was getting very tiresome making all the layouts programmatically, especially when trying to align everything nicely.
I liked using Visual Basic back in the day, so I'm making something that works along those lines.

Attached: visualbuilder.png (1440x900, 355K)

just got an A+ for a programming class I didn't read any of the material for

big baller status baby

Why should I comment my code if everybody who reads it should be able to understand it?

>doesn't do the same thing
he doesn't use the variable 'done' for anything, so I didn't have to deserialize it

commenting isn't about 'what' but rather 'why'.
when using an eso/obscure shitlang like haskell, comment everything regardless

Comimg from Python. What should I learn between Javascript or Typescript?

comments can lie and be outdated, type annotations won't, however.

Just learn JavaScript. TS is a Butts language. Nothing that claims to replace JavaScript or C is ever going to.

Today was weird at the office. I got in to see a stranger in my boss's seat. I asked him who he was and what he was doing there, and when he replied I realized from his voice that he was my boss, I simply didn't recognize his appearance because he ordinarily wears his fursuit mask and usually the body too because he's very shy. Turns out one of his suits got ripped at the dry cleaner and his spares were dirty and he was pissed about it.

I wasn't the only one, lots of other people did a double take (even the CTO) when they walked by our section of the office, including people who've been with the company much longer than I have. I feel a bit bad for the guy, his work was noticeably off today, I spotted far more potential improvements than normal when reviewing some code he submitted in the early afternoon.

good luck getting a dynamic language user to understand that point

>I simply didn't recognize his appearance because he ordinarily wears his fursuit mask and usually the body too because he's very shy.
Either really bad larp or you live in California.

Dynamic lang brainlets all eventually give in to static types.

>fursuit in Cali weather

>not using a language with no types
mov rbx, 1
mov rax, 1
loop:
imul rbx, rax
add rax, 1
cmp rax, 5
jl loop

I can't go back after having used Dependent Types.

use the Tardis: hackage.haskell.org/package/tardis-0.4.1.0/docs/Control-Monad-Tardis.html

No thank you.
docs.idris-lang.org/en/latest/st/state.html

I'm using python which is readable as fuck.

no it isn't

I finally got to the point where I can test my assembler against my hand compiled code
This weekend I might even add the ~floating point~ instruction set

That code is wrong. The right shift should be changed, probably to sizeof(signed int) * 8 - 1

It actually looks buggy, because the first half is for a 16-bit value, i.e. 0xFF is only 16-bits. But then it right shifts 31, which is very wrong for a 16-bit value.

That code is probably wrong.

>duck typed
>readable

JS is turning to TS so that is where your wrong, kiddo.

this prints out 1 8 - how is "what" 8 chars?

int main(){

char *f = "What";

char *g = malloc(strlen(f));

strcpy(g, f);

printf("%s\n", g);
printf("%ld %ld\n", sizeof(char), sizeof(g));

return 0;
}

TS is shit, at least use a good language like Elm or PureScript instead

because you're retarded.

It's not. You used sizeof which return the size of the pointer not the string. If your os is 64bit the program is performing exactly how it should and printing 8. What is this, the second or third Ctard in /dpt/ that wrote garbage today?

Attached: 1553714653742.jpg (482x482, 28K)

I don't even shit web, insecure esolang-er.

You are getting the size of the pointer, use strlen for that. Also you need to malloc(strlen(str)+1) to account for the null terminator, user.

Good job, keep going.

I recently wrote a script to auto-generate prototypes from a C file and stuff them into a header. At work we had things that got put into a local header for the file, and a second header for a group of files on similar tasks.

I'd like to make a thing to more easily automate an "object-oriented" interface, though I also want to test if directly storing a function pointer in a struct works for auto-completion, but gets inlined and removed from the structure by optimizations (since it'd be constant)

Attached: headerscanner.png (2555x1402, 367K)

I'm learning C++. I'm pretty familiar with C programming. Right now, I'm programming C++ as a """better""" C, using classes and vectors. Where do I go from here? What seriously differentiates these languages in a more professional setting? C++ seems to be a hefty, feature-laden language with support for several paradigms, but I haven't noticed that yet.

Broken and circular inheritance models, exceptions, partial comparisons, spaceship operators, who knows what

>What is this, the second or third Ctard in /dpt/ that wrote garbage today?
All me.

Attached: 1554736601143.png (682x682, 444K)

templates