/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Old thread:

Attached: 1534882259624-bant.jpg (800x1132, 432K)

Other urls found in this thread:

youtube.com/watch?v=bKWKDOiHVDw
twitter.com/SFWRedditGifs

depends on the lang. some lang have 16 bit char.

I'm using C. It takes the least significant bits right?

returning back to programming after 6 months of shitstorm...
>every code seems fucking new
>everything seems like umm..i think i know this
What to do guys?
I swear to god I'll never leave programming again?

i don't know C, but it sounds logical to take the LSB.

>I swear to god I'll never leave programming again?
Yes.

Attached: priest.png (231x218, 6K)

swear to god that you'll carry on terry's legacy.

Attached: terry.png (500x335, 347K)

What to load from a memory address is part of the instruction. Some operand sizes trigger clearing of the upper bits, some don't. Like I said, I think on x86_64 16 bit might be the exception.

It's implementation defined. It will probably truncate, but you should test it to be sure or look it up in the documentation.

Rewrite it in Rust!

God bless anime

tuhu is not anime

ty for posting cute 2hus instead of that disgusting thot OP!

Attached: 1508614738397.jpg (900x1800, 166K)

Attached: strongest power.png (1920x1080, 2.34M)

touhou is over-anime

I'm consuming kava and letting the anger flow.

he has no legacy.

learning c++ before i start my new job

cute 2hus

tfw it works

I was trying to do this and failing thinking UTF-8 worked like 1110XXXX 110XXXXX 10XXXXXX when it was 1110XXXX 10XXXXXX 10XXXXXX. I feel slightly less retarded now.

Attached: untitled.png (251x62, 1K)

Working on gamu

Thinking about efficient ways of testing if three bytes are the same. More efficient than checking a == b && a == c. Load all of it initially into one register.

a == b && a == c is the best solution.

a & b & c == a

I want to start small with a little problem I sometimes have. Sometimes I'll start typing in one language but forget to switch my input so I end up with a mess. How should I approach selecting a bit of text and making a program translate it to a different keyboard layout?

Don't you EVER talk shit about Belle Delphine

>posting 3dpd on anime board

incorrect

Can't go more efficient than that, I think.
Maybe write it as a == b && b == c?

Would that be more efficient? I'm not imagining register pressure, but in that case c could be written over b.

It's implementation defined but every single implementation I've ever touched takes the LSB yes.

It is fairly common to type pun with stuff like:

char *arr = (char *)&other_type

And have the LSB in arr[0].

post red flags for code
>unequal spacing (a =b;, printf ("asd%s\n",str ) ;)
>uneven indentation
int fun(void) {
fun1;
fun2;
fun3;
return fun4();
}

>no space between if/for/while and parentheses
>excessively short variable names that appear to have been chosen sequentially (a = ...; b = ...; c = ...) or by keyboard-mashing (asd = ...; hjkl = ...;)
>excessively long variable names (returnCode, arrayIndex, searchResult)
>variable names with numbers (string1, string2, string3)
I was just thinking of readability.
a == b is equivalent to b == a, so a == b && b == c is equivalent to b == a && b == c, which, swapping around the variable names, is equal to a == b && a == c.

Attached: 1517414753661.jpg (966x1200, 189K)

Learn to program properly, if you can't understand it after 6 months it's shit.

How do I start a new project? Out of ideas completely. Want something usable in Linux world ,not gui and in something that isn't C preferably.

>in something that isn't C
y tho

I don't want to do embedded and there hasn't been a single non embedded job posting requiring C knowledge this year. I'd prefer something modern and a bit more in demand

I really like Remilia

Emulator in C++

first year cs student?

You could do freelance work, or anything else really. C is comfy.
Or you could work in C++ and do much of the same.
Make a web something (e.g. comment system) in C++ with fastcgi and sqlite. Make sure to avoid objects and C++ anything religiously, and cast your malloc().
No, but I see a lot of code which looks like it was written by one. Especially by women "programmers".

why is making an emulator always recommended when people ask for project ideas

its a braindead project you can achieve by following a spec without any creativity

First two are arguably just mistakes. Even good code can have it.

>no space between if/for/while and parentheses
Pure style thing.

>excessively short variable names that appear to have been chosen sequentially (a = ...; b = ...; c = ...) or by keyboard-mashing (asd = ...; hjkl = ...;)
i/j/k/l, x/y/z etc. are completely legit names that serve their purpose and have obvious uses to anyone who's touched code for longer than a month.

>excessively long variable names (returnCode, arrayIndex, searchResult)
Only one I agree with. "retval", "index", "i" and "result" will do provided you contextualise them properly.

>variable names with numbers (string1, string2, string3)
Has legit uses, especially if you're filling out a struct for a hardware interface that has a weird layout, or constructing a network packet in a specific way. The IDT on x86 machines is an excellent example of such.

>a == b is equivalent to b == a, so a == b && b == c is equivalent to b == a && b == c, which, swapping around the variable names, is equal to a == b && a == c.
This whole thing is completely pointless. Anyone who's done any sort of maths will understand that:

a == b && b == c implies a == c
a == c && c == b implies a == b

etc.

The only people who don't understand this are those that suffer from overexposure to JS and other languages with systemic brain damage. It will always be the case in C.

Because there is nothing simple about creating accurate emulation.

raytracer

>i/j/k/l, x/y/z etc. are completely legit names that serve their purpose and have obvious uses to anyone who's touched code for longer than a month.
Yes, but code like this is a red flag:
int a = ...;
char b = ...;
char* c = ...;
float d = ...;

or utter garbage like this:
return hjkl+asd*2+c(g[asdf]);

>Only one I agree with. "retval", "index", "i" and "result" will do provided you contextualise them properly.
rc is standard already, retval is just too long. Same goes for index, idx or i depending on context is standard. result should usually be res or maybe qres/res_q.
>Has legit uses, especially if you're filling out a struct for a hardware interface that has a weird layout, or constructing a network packet in a specific way. The IDT on x86 machines is an excellent example of such.
Then why wouldn't you be setting the fields of the struct instead?
>This whole thing is completely pointless. Anyone who's done any sort of maths will understand that
Yes, but it's slightly less cognitive load. The brain interprets a == b && b == c to a == b == c slightly faster than a == b && a == c. It's just a style thing, but it looks slightly cleaner.

>I swear to god I'll never leave programming again?
this is so true
it hurts confidence man, you gotta work double hard when you making a come back
i don't know how i did it, but it feels like a fucking loser at first

Based quads.

Attached: 1507219275099.png (688x720, 349K)

these pure style autism triggers are non-issues and can be fixed easily with a formatter.

>result should usually be res or maybe qres/res_q.
??????????

half of those are typos

I get that after 2 days

Which figurines accompany you on your long coding sessions, Jow Forums?

Wireless devices and aluminum intake.

listen to this song and revision hard, user
youtube.com/watch?v=bKWKDOiHVDw
best of luck!

no thanks, I'm stuffed

operator precedence m'nigga. You basically wrote a & b & (c==a)

Are the cause of your poor memory.

Very rarely, result is appropriate if it can be confused with resolution, but usually, it should be named res, qres (query result) or res_q (result [of] query).
That's the whole point, they are red flags. If you see code like that, something else is bound to be wrong with it too.

What’s the point of generics

Attached: 0A50C6EE-00D0-4AD5-8ECA-83DAAE1814C3.png (141x145, 42K)

making typos doesnt make you a bad programmer

to avoid having to copy+paste code for different data types

anti-pattern meme shit mostly

trigger gophers

I know. I made a joke.

Poor attention to detail makes you a bad programmers. Not fixing those typos before committing is significant of poor attention to detail. Thus, code with such typos are significant of you being a bad programmer, a red flag.

if you have written any significant amount of code I can guarantee you you have forgotten a space before an =
does mispelling a variable name and getting it caught by the compiler make you a bad programmer too?
you're retarded

Or you just have all your attention on the actual problem at hand (or the thousands of other problems thar are still awaiting).
Do you also spend more time in the bathroom than in front of your computer? I take it you're just one of those w*men.

wtf everyone makes typos every once in a while

You have 1 point about committing a typo though, test cases or compilation should be picking those up, and you do that before committing

>Yes, but code like this is a red flag:
I agree, but I can't say I see code like that outside of people who are writing their very first few programs. Code like that is usually not published.

>rc is standard already, retval is just too long. Same goes for index, idx or i depending on context is standard. result should usually be res or maybe qres/res_q.
I've seen both rc and retval be used a lot between the open source projects I've read, as well as result. Personally I use retval, i, result. 6 characters is not too long.

>Then why wouldn't you be setting the fields of the struct instead?
Bitfields are not reliable. There is no guarantee about how the compiler arranges the bitfields.

What I am talking about is manually packing the struct's fields so that you don't rely on compiler attributes, pragmas etc. to properly align and pack your struct. Most C compilers won't pad or realign a struct if you align and pack it properly by yourself, and I've yet to see a single one that does.

The result is that you may end up having numbers in your variables because of the nature of the struct, because if you want to not violate the strict aliasing rule, and you don't want to do unnecessary memcpy etc. then you will end up relying on char.

>Yes, but it's slightly less cognitive load. The brain interprets a == b && b == c to a == b == c slightly faster than a == b && a == c. It's just a style thing, but it looks slightly cleaner.
I agree with you, yes.

No, but if you check it into git without noticing, that does.
Okay, so say you make a typo and accidentally switch == for =. You're still a good programmer, because the bug was unintentional?

I'm a good programmer because I use types that would've prevented that specific type of typo.

bugs are different to formatting typos
one matters, the other doesn't

>mfw typelets can't into typo safety

Attached: 1518462062934.png (700x668, 376K)

just jumping in, typos are a matter of mispelling, types has nothing to do with it

for typed languages, compilation or an editor would reveal this, for non-typed languages, the additional step would be running through interpreter

It's not a matter of "mattering" or not, it's a red flag, that's the whole point. If an obese fellow shows up for an employment interview in crocs, socks, cargo shorts, a hawaii shirt, a neckbeard, and sunglasses, does that seem like a respectable person to you? They might be for sure, but chances are there's a good reason they're unemployed.

>things that don't matter actually matter
>6 letter variable names are too long, using 'idx' is better than 'index', but don't make your variable names too short either
have you been diagnosed with autism?

Think about it, why is it no okay to say "We don't want you. You are a nigger", when it's okay to be like "We don't like your clothes, go away"

(a&b&c)==a would also be incorrect.

a = 0b0001
b = 0b1011
c = 0b0111

a ∧ b ∧ c = 0b0001 = a

Because one of them is illegal. In reality, African-Americans are quite poor coders due to IQ differences, although I would rather have an educated Black than an educated woman, since with the latter all bets are off, and you might get feminism in the workplace.
But it's not about the clothes, it's about the fact that if a person showing up for an employment interview wouldn't even bother to look presentable, what are the chances of them being a good employee?

You're telling me types wouldn't prevent
if(foo = bar)

instead of
if (foo == bar)

?

I bet you're a typelet yourself

go back to your klossie bootcamp, disgusting female.

what do types have to do with whitespace?

JavaScript rocks!

maybe read my post again dumbass, the whole thing

>Okay, so say you make a typo and accidentally switch == for =. You're still a good programmer, because the bug was unintentional?

I'm not a woman, I don't believe women should be in the workplace. But if you show up to an employment interview like that, it's a clear sign you don't give a shit about the job and won't take it seriously. It's like a woman being overweight or wearing a choker. There's nothing excessively unhealthy about either of these, but it does reveal the excessively low moral and social character of her.

>I don't believe women should be in the workplace
because they'd mock you for your mental illness?

Chokers signal that a woman is ready to be abused and dominated.

>retval is just too long.

6 characters is too long? It's not verbose and it's descriptive. What's the problem?

Can anyone please recommend me, a person who never coded before in his life a good beginner's guide to Python? I need to learn some basics for my job, but I can't really judge if the guide's good or not since I'm a complete beginner.

Attached: 1526875833852.jpg (500x420, 28K)

to be honest, I didn't even see that post. I was thinking of typos in the sense of words, rather than symbols. My bad

No, because they should be mothers.
It also signals that she is a thot.
It's too long because it's 4 characters too long. That makes it verbose. rc is standard, retval is just 4 characters' noise.

Way I started was just with Python's main website, then I took some challenges on some sites, like hackerrank I believe

Was enough for me to pass interviews

>thot
why do Jow Forumstards use niggerspeak despite claiming to hate them?

thanks, looking good so far

Attached: fMSBN1cMXFY.jpg (960x956, 112K)

so you're an incel /fa/ggot. Same thing really.

Is it legal to free() a static char array?

Help me out here? I'm just trying to read string form input and dynamically allocate mommy in a function.
The printf at the end of the function always prints the correct string but I also have one print in main, right after the function ends, and sometimes it prints correctly, sometimes just first few symbols and sometimes just gibberish. Why?


void get_string(char *string)
{
int i;
char ch;

for (i = 0; (ch = getchar()) != NEW_LINE; i++)
if (i < MAX_LEN)
{
string = realloc(string, (i + 2) * sizeof(char));
*(string + i) = ch;
*(string + (i + 1)) = '\0';
}
else
*(string + i) = '\0';

printf("end function %s\n", string);
}
[!code]

Pretty sure you'll get arrested on the spot m8

No. free only works for pointers obtained from malloc.