/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

tutorialspoint.com/c_standard_library/c_macro_assert.htm
twitter.com/NSFWRedditGif

Rust is dead

They are different languages and both should be used differently. One of the reasons people are so confused with c++ is because they are thought to think like they are programming C with extras.

fucking faggot

What editor is that?

I don't know, but you should use Code::Blocks

looks like notepad++ with all the default settings

Finished my college now im Going to start looking for a job as fresher.
What language should i concentrate on Sup Forums?

See

Java EE unironically
Then learn JS and angular.

fpbp

>you should use Code::Blocks
lmao no

Thanks, it looks like shit, just trying to figure out what to stay away from.

If you didn't do internships and get hired straight out of university, you literally wasted your time.
You better hurry the fuck up because once your work history gap is greater than 6 months, you're gonna start getting trashed even with a degree on your resume.

Daily reminder that sepples monkeys usually don't understand sepples.

template
void foo(std::function f) {
}

int f(int x, bool y, float z) {
return 0;
}

int main() {
foo(f);
return 0;
}

Explain what's wrong with the foo call, then show the shortest way you can think of to get it to work without changing anything about the definitions of foo and f.?
(Note that the correction.)

>looks like shit
IDE is for being functional making shit done, not for staring at it. Maybe it's good that faggots like you who never made a real program stay away from Code::Blocks

If you want to earn money and learn something easy then go with python

This, I got a job offer on first semester because I got into in our university's competitive programmer team.

Friendly reminder that you need 5 different header files and 2650 lines of code if you wanna animate an inverting tetrahedron in "modern" OpenGL.

When will C cucks learn?

you have to do the same in every language or use library doesn't change the fact that opengl sucks

Friendly reminder that you only need 40,330 lines of code to animate a 6-dimensional non-euclidean inverted dodecahedron in modern OpenGL.

For some reason the variadic template parameters put it in a non-deduced context, I couldn't figure out why.
The shortest fix I can think of is to explicitly cast f.

Next challenge please.

>I couldn't figure out why
Too bad.

>The shortest fix I can think of is to explicitly cast f.
That's by far not the shortest fix.

>Next challenge please.
Once a sufficiently large number of sepples fans fail at it.

are booleans even real?

No, they're discrete.

kek

no

Does C++ pack booleans to fit them 8 into a byte, or does it waste the whole byte on each one?

std::vector is a specialization that packs them.
That was a huge mistake, btw.

depends on compiler

>are booleans even real?
They're actually just ints, so there is an imaginary component.

implementation specific

the standard mandates it lol

What are you working on where that would be a waste

>They're actually just ints, so there is an imaginary component.
wat?

You think you're entitled to all the available ram on your user's machine just because you're a terrible programmer?

What are you working on where that would be a waste

You think you're entitled to all the available CPU cycles on your user's machine just because you're a terrible programmer who does needless bit ops?

...

Is there any way to make the java compiler compile illegal code?

>75) sizeof(bool)is not required to be 1.
Doesn't that mean the implementation is free to choose how it's stored?

sup johnson

More like 500 LOC, you've just been OOP-memed.

When I say it looks like shit, I mean in the context of the purpose.

It looks extremely limited in functionality.

college freshman that wants it to "just fucking work" detected

shoulda went with c or C++ instead
there's atleast a dozen ways in those languages

you are incorrect

Daily reminder that sepples monkeys shill for a language they don't understand, and then get angry when people who do understand it advice against it.

Are you fucking stupid?

C++ doesn't hold your hand. If you want it to be packed like that, do it yourself. A C++ bool is usually as long as the compiler deems necessary for efficiency.

Is there any way to control the rendering framerate in glfw?
Right now anything I do in glfw eats up a whole processor core, and they took out the sleep routine because apparently C11 threads were on the way and you're supposed to make threads sleep on your own.
Am I seriously expected to add pthreads as a dependency if I want to mess around with opengl?

If it won't compile then fix it you nigger.

Yes, make the illegal code legal, retard.

>Is there any way to control the rendering framerate in glfw?
Yes. Use conditional directives to write your own sleep function that calls whatever a platform provide natively.

but i want it to be illegal on purpose to see what happens :^(

What do you expect to happen?

Why do you expect anything to happen beyond an error/crash?

Stop.

It doesn't fucking compile, that's what happens.
It's impossible for the compiler to decide what should happen at runtime because it's not fucking valid java code to begin with.
How is it supposed to know what to do with not-Java code? At that point you cant even really call it code, it's just arbitrarily formed text that happens to look like Java but isn't Java.

Or just call glfwSwapInterval(1).

It doesn't do anything, it'll continue to eat up 100% even when rendering nothing.

illegal java code is NOT JAVA CODE

There are some thing that it will arbitrarily decide not to compile like setting a boolean to an int which should theoretically be possible with no problem

Will anyone here be taking advantage of the new java features that will come with java 9 when it comes out later today?

On windows that doesn't work for reasons.
And I'm not entirely sure if it yields on any platform.

Reminds me of my freshmen year at the university.

Good times, despite all.

I don't know what the problem is supposed to be. You do exactly the same thing you do with any other functionality that the standard doesn't dictate: you use whatever the platform provides.

I don't get it

He's asking for if there's a canonical way within glfw to set a framerate.
I don't think user doesn't understand how to measure time and sleep for an appropriate amount of time.

>not using SDL
your own fault

Does Sup Forums unironically wear these gay socks?

>if there's a canonical way within glfw to set a framerate.
I think two separate issues are being conflated here. Capping the number of times you make your draw call per second is one, preventing the rendering loop from eating every available CPU cycle when it's not doing anything is another. Neither one has a "canonical glfw way" as far as I know.

>girl using computer
>gay
k

If you think that's a girl, you're clearly a newfag.

You're not a girl

Internships during university are not always possible.

To clarify, if you want an FPS cap, the most obvious way is to do something like this:

double last_render_time = get_time();
float frame_accum = 0;

while(!exit) {
double curr_time = get_time();
frame_accum += FPS * (curr_time - last_render_time);

for(int i = 0; i < (int)frame_accum; ++i) {
render(1/FPS);
}

frame_accum -= (int)frame_accum;
last_render_time = curr_time;
}


However, this will still eat up CPU cycles. To prevent that, you'd do a sleep(0).

>also a degenerate

like java wasn't enough of a reason to gas that faggot

Is there a better way for me to value the letters than all these case statements or is this pretty much the best way?

//Returns the "Scrabble value" of a word
#include

int valueChar(char c);
int main(int argc, int argv[]) {
int sum = 0;
char c;

printf("Enter a word:");
while((c = getchar()) != '\n') {
sum+=valueChar(toupper(c));
}

printf("Scrabble value: %d\n",sum);

}

int valueChar(char c) {
c = toupper(c);
if(c < 'A' || c > 'Z')
return 0;
switch(c)
{
case 'A':case 'E':case 'I':case 'L':case 'N':case 'O':case 'R':
case 'S':case 'T': case 'U':
return 1;
case 'D':case 'G':
return 2;
case 'B': case 'C':case 'M':case 'P':
return 3;
case 'F':case 'H':case 'V':case 'W':case 'Y':
return 4;
case 'K':
return 5;
case 'J':case 'X':
return 8;
case 'Q':case 'Z':
return 10;
}
}

Look-up table if you're bored.

You can build a perfect hash function using graphs, if the cases are static.

It's not so much that it doesn't work as they disabled it unless you set a define. Because there were issues with the platform when having desktop composting enabled. Which makes sense if you read into it. But if you rely on the swapbuffers call to block you're not gonna be too happy about this as you're now not locked to the screen refresh rate.
Yeah.

>Is there a better way
Yes:

int valueChar(char c) {
static int values = {1, ...}; // Put one value for every letter (in alphabetical order)
c = tolower(c);
assert(c >= 'a' && c

that's a compiler error

Well, shit. It should be: static int values[26] = {...};

I'm guessing user might need this explained to him if he's asking this question.
He shouldn't be afraid of looking stupid by asking.

> c = tolower(c);
ick

>Internships during university are not always possible.
yes they are; for winners

You contradicted yourself using five words, my congratulations.

>implying there's anything wrong with it in this particular context

>assigning to parameters

I think I understand, but why is this better? You still have to manually put in the values for every letter. I guess this is a more optimized approach? Also what does the "assert" keyword do? I've never seen that before. I'd assume it just returns immediately if whatever in the parentheses doesn't evaluate to true, but what value would it return?

Yeah user should have written

int valueChar(char C) {
char c = tolower(C) ;

>repeatedly typing out "tolower(c)"
>creating canonicalized copies of the arguments while leaving the old ones laying around be used by mistake
>somehow better than canonicalizing the arguments at the very beginning of the function and forgetting about the issue
Still waiting for a rational argument. All I'm getting so far is religious dogma.

tutorialspoint.com/c_standard_library/c_macro_assert.htm
It's basically 'crash my program if this is false'. For safety.
>why do this
It's faster because it doesn't have to branch (jump between conditional paths) a bunch. And instead just looks up the value in an array (a lookup table). But really you shouldn't bother with this if you're not comfortable with it. It doesn't really help you in any noticeable way. Don't worry about it.

kek

SC freshman here.
How long until all brainlets and memers drop out?

never
CS is for brainlets

Also, the sheer idiocy of having two different variables named c and C... and you're telling me what I "should have written"...

Gotcha, yeah I see how that would be much less expensive computationally or whatever. Last question: wouldn't that assert statement cause the program to exit if the word is entered with a leading or trailing space? Like if the input was " word" or "word ". Thanks for the help, user

You can't take a joke? A very obvious joke.

I mainly develop in C# at work.

I've been using Windows Forms for the longest time for GUI.
What other GUI systems compatible with C# does Sup Forums recommend? Or do you recommend keep developing in Windows Forms?

Answer me so I don't have to pollute Sup Forums with a new thread.