Dpt/ - Daily Programming Thread

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

Other urls found in this thread:

raywenderlich.com/148448/introducing-protocol-oriented-programming
twitter.com/SFWRedditImages

best way to learn OpenMP?
need to learn it

openMP is dead, learn chapel.

Significantly larger, but also 5-10 times faster. Keep in mind C can't just print data structures like python, so comparing the entire code size is kind of unfair.
int cmp(const void *ap, const void *bp) {
int a = *(int*)ap, b = *(int*)bp;
return (a < b) ? -1 : (a > b);
}
void* generate_primes(int end) {
char primes[end];
memset(primes, 0, end*sizeof(char));
void *set = 0;
for(int i=2; i

>Skills:
>Java/JavaScript - excellent

Nothing wrong with Java there. I wouldn't use it for hobby projects but it's the JVM that makes it so valuable

There's a lot of actually decent jobs writing server-side Java

Thank you for making a non-Pajeet /dpt/

>5-10 times faster
Surely its more than that.

A simple express app for my portfolio. It's 2017 and user authentication is still a total pain in the ass. Using Auth0, because I didn't feel like making a whole new database for usersm writing auth logic, etc.

>This'll take 15 mins. I just used it in Angular the other day.

2 hours later, I finally got it running. Fucking JWT's. Mobile web ruining shit for everyone as usual.

...

What are keywords to look for in job postings if I'm searching for a non-developer code monkey job?

Job posting
>Junior C Developer wanted
>Must have 4 years experience with C#

I really thought this was just a meme

fucking lol

Proof that C# is deprecated

I saw one that was
>Junior dev position
>3+ years with Android
>4+ years with iOS
>at least 8 years working with Java in a professional environment
>pay 50-60k, but GREAT benefits!!

The reason it's not even faster is because I used a tree based set rather than a hashset.

Which is actually really sad on python's part, that it still loses by a massive margin even when the C code is O(log(n)) instead of O(1). In practice, log(n) doesn't matter since you'll run out of memory before log(n) gets big, but what log(n) means in practice is a really high constant factor - because you're running some iterative code to binary search or travel down a tree.

And python still lost...

should I read K&R, or Practical Programming?

Why not just use OAuth? That's what it's there for.

yes

>And python still lost...
So you measured?
What's the result.

After modifying the code to print one line same as the python:
me ~/Documents $ time python circ.py

real 0m0.619s
user 0m0.500s
sys 0m0.064s
me ~/Documents $ time ./circ

real 0m0.112s
user 0m0.108s
sys 0m0.000s

Thanks Coq.

ty

if (n[i:] + n[:i]) not in primes:
how does is_curcular have access to primes? its not in the function scope. or is python literally cancer/

Python doesn't actually try to read variables until runtime, so what happens is, when primes = happens a few lines down, gets set up so that when that method gets called later, it doesn't throw an error.

The primes variable inside generate_primes is an unrelated one that happens to have the same name.

jesus christ

Learning assembly, little confused about where to learn what syntax with what compiler. Just used a random x86_64 I assume is intel's and nasm, but I don't want to dump money on books for something I probably won't end up using much. Any online resources or torrents out there that anyone would recommend?

You read the reference manual.

It's not much different from C in this case, besides the lack of a declaration - the only main difference is you're throwing away compile time errors for not much benefit.

This is one of the reasons why I think python's a great language with great builtins that can't be evaluated quickly and doesn't always scale well to large projects. (although it might better than C)

Now what's really different is closures. If you're not familiar with that, it'll be a mindfuck. I think they're great though. I just want them with a strong type system. But writing stuff like is fun once in a while.

I used wikibooks and wikipedia, but I learned the fundamentals of assembly from 0x10c before moving to x86. Intel syntax is a lot easier to read, just use nasm.

And yeah I should add to , I got used to reading shitty/obscure sources of information when good tutorials ran out

having just learned about the power of git
how long does the "git init all the directories!"-stage last? or is it a lifelong endeavour?

why shouldn't I just use auto for everything in C++11?

You should prefer auto in most cases.

Never initialize an auto-typed variable with a braced initializer list.

I want to know the following:

( current slope * 100/ max slope)
how would you look for the current slope with a class such as this?

class EarthLandscapeColors implements LandColorizer {


EarthLandscapeColors(){

}

public RGBColor computeColor (float height, float slope, TerrainInformation info){
int brightness = info.brightnessForSlope(slope);

if (height

thanks, I was scared of it for some reason. Seems like magic, it's all compile-time costs?

What does that do?

Yes. The compiler can easily infer the type of a variable by what you initialize it with.

Just started using swift for some iOS programming at work, it sucks and I miss F#. Why is swift being shilled as the future of programming?? Someone please explain.

Because your IDE a shit and can't deduce type itself.

>programming with an IDE

std::initializer_list type

lmao

you can of course go auto d = double{1.23}; to avoid that but then why use auto in the first place?

why would you use an initializer list for a single double?

it's just an example, you can try to initialize whatever, it'll be deduced as an std::initializer_list

if i have no other work experience is it worth putting that im working a factory job on my CV when applying for tech and programming jobs? i dont want to add something to my CV that would make me look bad

Changed in C++17.

so auto foo = {2, 3, 4, 5}; is deduced as an int[4]?

#include
int main()
{
char c;
while ((c = getchar()) != EOF)
{
if (c == '\t') printf("\\t");
else if (c == '\b') printf("\\b");
else if (c == '\\') printf ("\\\\");
else putchar(c);
}
}

This code works.
However, if I remove the "else if" statements and replace them with "if" statements, then input a tab, it'll print \t then print a tab, even though printf("\t") is supposed to just print "\t".
How come?

Previously:
auto a = {42}; // std::initializer_list
auto b {42}; // std::initializer_list
auto c = {1, 2}; // std::initializer_list
auto d {1, 2}; // std::initializer_list


Now:
auto a = {42}; // std::initializer_list
auto b {42}; // int
auto c = {1, 2}; // std::initializer_list
auto d {1, 2}; // error, too many

How do people defend this garbage language?

uniform brace initialization syntax was a mistake

Y- you get used to it.

there's nothing better

probably because it prints the "\t" and then putchar prints the tab.

But puchar is inside an else statement, so isn't it supposed to be called only if c isn't equal to any of the aforementioned values?

Also use a switch statement for this sort of thing. Or if you want to be a real G make a lookup table using ASCII values.

Think of it like this:
// c == '\t'

// Does c == '\t'?
if (c == '\t') {
// Yes, print \t
printf("\\t");
} else {
}

// Does c == '\b'?
if (c == '\b') {
printf("\\b");
} else {
// No, do nothing
}

// Does c == '\\'?
if (c == '\\') {
printf ("\\\\");
} else {
No, print c, which is a tab
putchar(c);
}

You visit every if statement, and on the last one it executes the else branch because c == '\\' is obviously false.

Well, I'm only at the start of the book, so I don't think I'm supposed to use anything complicated. Switch would indeed be better though.
Alright, I get it now. Thank you.

Nah, the else will only apply to the "if" immediately before it

That's cool. It's not too hard though. The idea is you place your characters in an array and use the ASCII values to retrieve them.

e.g. vertical tab has an int value of 9 so you can use the char itself to access the array (+ whatever offset depending on the size of the array) to get the character that you need

Knowing about ASCII values and treating chars as numbers will help a lot when dealing with strings in C

woops, meant horizontal tab

I've been drinking

I see. I'll look into ASCII values eventually since I don't know shit about that.

>tfw too scared to compile

What is this disgusting shit?

raywenderlich.com/148448/introducing-protocol-oriented-programming

why

is this a new meme

What if it doesnt work and I dont know why

That's not part of the compiling process, that's part of the testing. Unless you can't solve syntax errors in which case you are a beginner and you should git gud.

but once I compile I will have to test
Thats where the true horror begins

>mfw it actually works
I did it boys

So you are not afraid of compiling, you are afraid of testing your shit. The two are different.

>So youre not afraid of fire, you are afraid of burning to death. The two are different

Horrible analogy. Try again.

t. BTFO

t. cant program lol

but it is a bad analogy.

a fire is active, meaning in this case the program has already been compiled

the proper analogy would be

>So you're not afraid of starting fires, you're afraid of experimenting with fire

most people are not afraid to light a fire, but throw shit in the fire and making sure it doesnt explode does lead to some fear

this translate to

most people are not afraid of compiling, but adding untested shit into the program and making sure everything works correctly does lead to some fear

lighter = compiler
fire = untested compiled program

Nice reddit spacing, fag.

>reddit spacing
this is the dumbest shit i've seen posted on Sup Forums.
I space my sentences for clarity.

fuck off

I would've thought that most of the people on Sup Forums would actually sit down and consider logic but it turns out shitposters reside here too, huh

>shitrunner

Putting every single sentence into a new paragraph is the opposite of readable, you are supposed to create paragraphs that consist of multiple sentences that follow the same train of thought. Arbitrarily hitting the return key twice every few words makes your post very irritating to read.

You need to leave.
>clarity
Putting a bunch of extra wasted space and breaking your lines in random places does not make your post more clear.

he must've been hitting the enter key all day, it's probably inbuilt muscle memory at this point
This would work fine on messaging platforms but unfortunately, we're not on one

>clarity
Are you retarded?

but it is a bad analogy.
(end clarity)

A fire is active, meaning in this case the program has been compiled. The proper analogy would be:
(end clarity)

>So you're not afraid of starting fires, you're afraid of experimenting with fire
Most people are not afraid to light a fire, but throw shit in the fire and making sure it doesn't explode does lead to some fear.
(end clarity)
This translates to:
Most people are not afraid of compiling, but adding untested shit into the program and making sure everything works correctly does lead to some fear.
(end clarity)

lighter = compiler
fire = untested compiled program

I fixed 2 spaces, otherwise it's perfect as is.

You're deliberately trying to stop doing it now. Your lack of capitalisation and punctuation (especially at the end of each line) is still giving you away.

Fuck off.

>We are making a web browser!

what

That's not him you delusional moron.

he's retarded and thinks im you based on something idiotic.

>exactly one minute apart
Nice samefagging pajeet

...

I agree with you. I've been on Sup Forums since around the Cracky-chan fiasco. I don't even have a reddit account.

And yet, suddenly the way I've always posted is "reddit spacing".

I just want to talk about programming.

>What are you working on, Sup Forums?
Discovering the wonder and horror of using M.

>I don't even have a reddit account
This is basically admitting "I am a redditor, I just don't post".
Fuck off.

wow, nice, you know how to edit html

shut the fuck up

brainlet

And thank you for confirming that I was 100% correct.
Fuck off.