/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1529574461617.png (916x984, 626K)

Other urls found in this thread:

ziglang.org/
racket-lang.org/
i.imgur.com/s9fBFs0.png
youtube.com/watch?v=3MB2iiCkGxg
files.catbox.moe/82mjcw.jpg
github.com/free-language/Computer-Systems-A-Programmer-s-Perspective
twitter.com/AnonBabble

reminder that C++ is the most powerful language in the world

#include

void foo() {
// This code compiles
std::string(bar);
}

Attached: 1536917431584.png (1000x928, 128K)

That frog is teh sux0rz

previous thread already reached the bump limit? damn. umaru edition are definitively the best of all editions.

Attached: umaru.jpg (640x961, 292K)

Is there any way to implement dinamic arrays in python?
If i am not mistaken i remember i used to do it on c++.

OK I want serious answers.
What language should I learn to replace C?

dumb frogposter

dumb ratposter

Learning Haskell.

void fuckOffFaggot() {
std::string (((You)))((("there is literally nothing wrong with this code, why are you so retarded?")));
cerr

do you want a language like C but better? ziglang.org/
not necessary like C? racket-lang.org/

Starting to learn to program. Chose C as my first language as I already have a decent understanding of programming concepts. Current books:

>The C Programming Language
>C Primer Plus, 6th Edition
>Programming in C

It's purely as a hobby though, fuck wagecuck programming.

>dinamic arrays
Is this bait? All arrays are dynamic in python.

I just want to kode like a kloss

Attached: isdiv.png (385x127, 12K)

i.imgur.com/s9fBFs0.png
This is the problem. Some linters will catch it but still sucks ass

>Uploading files from you ip range has been blocked due to abuse
Fuck some nerd using the same 4g range as me

Nice. That's a good way to learn something.
If you want to learn something solely because of money - you're going to be pajeet tier at it.
However, if you take a different approach and make it a hobby - you'll surely learn much more with shorter amount of time.

learning django

I mean you declare a array as
A=[]

right?
But when i try to insert a value on it it says that its out of range?

>posting a link to the image instead of including it with your post
What.

I don't know what I wanna do
go read Bjarne's book or try making one of those roll projects and looking shit up when I'm clueless how something works

Attached: 1531346541944.jpg (688x529, 44K)

Attached: wrong.png (439x48, 11K)

>Uploading files from you ip range has been blocked due to abuse
are you finnish by any chance

Attached: 1448170874602.jpg (249x265, 23K)

I wrote right there why I did it...

void Obj::update() {
unique_lock(m_mutex);
mutate();
}
realized there's a code block too

A = []
A += [10]
A += [100]
print(A)

I sure am. How did you know?

24th for fuch anime.

Wew. ZIG looks pretty good. Cant say I like rhe syntax but otherwise it has nice features. I will check zig out.

perhaps that's due to your gayposting countryman on Jow Forums, supposedly got his entire province blocked

>Racket

Attached: 1522871587492.jpg (485x443, 51K)

28th for fuck anime girls

wew. Faggots ruining it for all of us again

This is a local mutex:
void Obj::update() {
unique_lock(mutex);
mutate();
}


This is a lock.
void Obj::update() {
unique_lock(lock)(m_mutex);
mutate();
}


This is a local mutex that has the same name as your member variable.
void Obj::update() {
unique_lock(m_mutex);
mutate();
}


I really don't see the problem.
What else is unique_lock(m_mutex); supposed to do? call the constructor like this?
void Obj::update() {
unique_lock lock = unique_lock(m_mutex);
mutate();
}

You realize that a cast without an object to asign it to will be an rvalue refference and just deleted on the spot, thus not locking it at all?

oh
Holy fuck thanks, i ve been researching how to do this but i really couldnt find.
I was doing
i=0
f=int(input())
while i < f

A = [i]
i = i + 1
A[i] = input()

just use the god damn append

Attached: 1514574946447.jpg (340x565, 46K)

>been on Jow Forums for over a decade
>can't even write a simple hello world program

Attached: 1523445210895.jpg (640x845, 108K)

As a fellow hobby c programmer i recommend the following order.
Start with:
>Learn to Program with C Noel Kalicharan
then
>Programming in C by Stephen G. Kochan
After
>Computer Systems: A Programmer's Perspective

I want to work for Amazon

I’m a cuck dropout but plan on finishing my degree online at some point

Is learning Java then AWS a valid path to reaching some sort of low level position there?

I have a C function float*** fun(){...}. it returns of course a pointer array, which is declared in the function, the memory allocated and given values correctly representing a 3 dimensional array. I can use array syntax array[0][0][0] inside the function and retrieve the right value. What I can't do however is, in main(), float*** array = fun(); and actually get values using array syntax (or pointer arithmetic syntax for that matter either). Doing that declaration causes no issue, but whenever I try to print out eg array[0][0][0] it runtime crashes.
Does this have anything to do with it not liking triple pointers? Why would that be an issue? I'm not very good with pointers but I still "get" them. I have other functions that only return a float** rather than a float*** and use them perfectly fine. I don't know what makes this one not work.

I realized my own mistype in the first and third case.
Those are local locks that aren't initialized. Not mutexes.

It's too easy to think it's actually a function. It could be a handle* unique_lock(m param)
instead of a class constructor.
Ambiguity which is a pretty big problem in a lot of c++ code.

Post your function. Probably allocated on the stack if I had to guess.

If you declare a local variable, the variable goes out of scope when you return from the function in which it is declared. It's probably that.

did you allocate everything on the heap?
also post code (reduce it to a minimal example if it's too big)

C++ is when you get the same exact answer with a 10-second difference from 3 different people in 3 minutes after posting it.

Yeah, in other words, c++ is bloat.

Attached: 1552363284706.gif (478x350, 84K)

Whay aren't you writing more comments?

Attached: 1554311936627.png (1299x550, 50K)

I'm sorry I don't understand your example. Care to explain?
You mean it could be a function instead of a constructor, right? Or am I missing something else?
I get that C++ syntax is ambiguous, even compilers struggle with it.

I don't write code to comment on
It's also bad to comment on others' code unless their code sucks, in which case it's mandatory to add sarcastic remarks in a comedic manner

>more comments than code
are you a haskell programmer?

That particular example would be exactly the same in pure C

Linters should warn you if you ever write Type(exprs...)

thats some garbage code right there

Anyone with experience with gitlab?

I have my code on a repository in gitlab but when i try to open my gitlab server on local-host it shows:

GitLab is not responding (502)
Whoops, GitLab is taking too much time to respond.
Please contact your GitLab administrator if this problem persists

Attached: blue017.jpg (100x100, 5K)

C doesn't have constructors, no one would be surprised that a lock wasn't taken because no function had been called.

Thanks for the advice. I actually have Computer Systems: A Programmer's Perspective, so it's good to know I'm on the right lines.

well you could learn in 3 minutes

Yeah exactly that. In the wild you never see lock(a), but lock a. The whole parenthesis feel to be there only to fuck up people. It's not used, it's not needed.
Yeah there are linters that would warn about this.
This is actually from
>Curiously Recurring C++ Bugs at Facebook
youtube.com/watch?v=3MB2iiCkGxg

Came across some when doing c++ myself. Those really are things you'd never think are there. 'useful' shortcuts that end up shooting in the foot. A lot of it remains for backwards compatibility I'd think.

Attached: 164.png (669x426, 39K)

Don't piss off a serial killer.

I'm out on my phone so I can't get to code. But I think maybe the issue is . I do have some pointers declared inside the function, but why should that matter? They're just addresses, how can they go out of scope?

also my mobile is rangeblocked from uploading images so here's this
files.catbox.moe/82mjcw.jpg

working on a nanopass compiler in C (each pass in a separate executable) because i'm masochistic

Its really a key book if you want to get good at programing.
Everything else is math.
I wish someone told me sooner about it I wasted a lot of time reading garbage books until someone mentioned it randomly in a post.
Just make sure you do the exercises.

Also, I went through the
class FuckedUpClass{
float* data;
float** data2d;
float*** data3d;
public:
float**** data4d;

FuckedUpClass(int x,int y,int z,int w){
data = new float[x*y*z*w];
data2d = new float*[x*y*z];
data3d = new float**[x*y];
data4d = new float***[x];

for (int i = 0; i < x*y*z; ++i)
data2d[i] = &data[i*w];

for (int i = 0; i < x*y*z; ++i)
data3d[i] = &data2d[i*z*w];

for (int i = 0; i < x*y*z; ++i)
data4d[i] = &data3d[i*y*z*w];
}

~FuckedUpClass(){
delete[] data4d;
delete[] data3d;
delete[] data2d;
delete[] data;
};

phase myself.
Be careful to not get memory leaks. It is often best to use just a 1d array and then accessing the values via
data[x*sizeY*sizeZ + y*sizeY + z] = 133.7f;

instead. It's not slower, as [x][y][z] just boils down to pointer arithmetic that just does the exact same thing under the hood.

Also, if you are just starting out with C++ it's best to use std::vector in the beginning, it will serve you well for everything you may want to do.

if you declare a pointer in the function and then return a pointer to it, the one you declared in the function is no longer around and the memory where it's stored may be overwritten
did your compiler give you a warning about returning an address of a local variable?

Well x*y*z and x*y*z in the second and third loop should be x*y and x instead. fuck me

and fuck the missed paranthesis.
class FuckedUpClass{
float* data;
float** data2d;
float*** data3d;
public:
float**** data4d;

FuckedUpClass(int x,int y,int z,int w){
data = new float[x*y*z*w];
data2d = new float*[x*y*z];
data3d = new float**[x*y];
data4d = new float***[x];

for (int i = 0; i < x*y*z; ++i)
data2d[i] = &data[i*w];

for (int i = 0; i < x*y; ++i)
data3d[i] = &data2d[i*z*w];

for (int i = 0; i < x; ++i)
data4d[i] = &data3d[i*y*z*w];
}

~FuckedUpClass(){
delete[] data4d;
delete[] data3d;
delete[] data2d;
delete[] data;
}
};

>[x][y][z] just boils down to pointer arithmetic that just does the exact same thing under the hood
not necessarily, if you access a float*** like that you'll get three indirections
it's only equal if you access a float[X][Y][Z]

If I want to get the book should I get the first or 2nd verison?

>I do have some pointers declared inside the function, but why should that matter?

Pointers are just 64bit integers under the hood. When the function ends, they get all deleted.
Everything that you didn't allocate with new gets deleted.
You have to do it like this

im reading the second edition currently.
That was the one available at library genesis so thats the one im reading.

what was meant by this
github.com/free-language/Computer-Systems-A-Programmer-s-Perspective

Ah, yes I didn't think about that.
float*** x;
float** y = x[1337];
float* z = y[137];
float res = z[17];

this is 3 derefferences.

float x[20][200][2000];
float y = x[17][137][1337];

this is arithmetic because the sizeof is known.

So
data[x*sizeY*sizeZ + y*sizeY + z] = 133.7f;

is always faster? I get it now.

unironically thanks a lot.
I have been failing to understand this simple concept for years now.
Don't get me wrong, I knew what all of those things do and how they work. But I just never realized that higher dimensional arrays are slower if accessed this way precisely because of the indirection. Holly fuck.

it's not because "the sizeof is known", it's because the results are different types when you dereference a float*** and a float[x][y][z].

Thats pretty cool.
Thanks for sharing.

sure, but under the hood. The reason is that float[Y][Z]; has a fixed size, and so the compiler can just optimize
data[x][y][z] to ((float*)data)[x*Y*Z + y*Z + z];

Hi friends. I'm building a REST API framework in C++. It's coming together nicely. However, I can't get std::variant to get it to see the proper function with std::holds_alternative, std::get and std::get_if.

This is where I check what function it is:
void HttpServer::enlist(EndpointWrapper *endpoint) {

using namespace std;

Endpoint *ep = static_cast(endpoint);

variant<
function,
function,
function,
function
> v = ep->lambda;

if (std::holds_alternative(v)) {
cout

Got a couple of weeks before my next client contact starts so I'm deciding between side projects.
I've always wanted to make a crossplat mspaint clone but I figure it will take longer than the time I have.

You're supposed to use std::visit. It's pretty shitty and you'll need some extra boilerplate to make it work, but it'll do in this case.

Yeah I read about std::visit. What's the reason though that it will never recognize is as a std::function though?

Im 99% sure that it is. It won't recognize it as any other of the possible variants and it ain't a nullptr so it has to be something right?

The std::any object will be read as:
St7variantIJSt8functionIFPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEvEES0_IFS7_lEES0_IFS7_S6_EES0_IFS7_P10RESTObjectEEEE

To add to that, I've succesfully used std::holds_alternative in my JSON parser which still needs cleanup but atleast its workable

looks as autistic as vertx desu

When the standard sais that std::unordered_set is "generally less efficient at iterating through a subset of their elements", do they mean proper subsets specifically, or any iteration at all? If I only want to ever iterate over -every- element at once, will std::set still be faster?

To prevent any confusion I'd like you guys to know that my preferred pronouns are he/his, and we as a community are free to draw the line in excluding these intentionally misgender me.

Attached: r_rust.png (973x474, 36K)

If you have an array of things and you want to do something only to the first N of them, do you write a single loop that checks "if i < N" in it, or do you write 2 loops, with the first doing N iterations, and the second's starting index being N?

for (array) {
if i < n {
doThing(Arr[i]);
continue;
}
doOtherThing(Arr[i]);
}

vs
for (N) {
doThing(Arr[i]);
}
for (i := N; N != Arr.Length; i++) {
doOtherThing(Arr[i]);
}


Please don't make fun of me.

Attached: 4a55706c0c672a641dcf10e815d959b074fa04acaec726d95d1077d558d7766c.png (500x430, 49K)

Figured it out halfway. Turns out it is a std::function pointing to a nullptr.

Imagine being this retarded

>and we as a community

Attached: we.png (412x405, 291K)

>mispronounce WE

>finally started using Java 9's "var" syntax
Can't shake the feeling the code is slowly becoming less and less legible, but boy does it feel good

the second one might be slightly faster
I think I'd prefer the second one because it's corresponds better to "do this to the first N, then that to the rest"

void f(){
int x;
x=84;
cout

>I just want to kode like a kloss
Then:

return !(n%3);

This is undefined behaviour. You cannot rely on it working.

boomer lang

try it with -O3

You absolutely need a degree to work at Fang, even fortune 500

Not an online degree, a university degree

No comments is better than wrong comments, like when you change something.

What kind of project do you guys do when you want to practice a new programming language, framework and etc?

I Need to learn Vue.js but i have zero idea on what kind of personal project i should do and i have no idea of what i should use for back end. I've been a front-end programmer for a while but that's all i did and now i need to learn more stuff. But i am so stuck on a front end mentality that i have no clue on what to do.

Pic unrelated.

Attached: 1549225175189.png (3000x1680, 2.31M)

I've been trying to dabble in web stuff. The idea is to create a simple site with a shitty login system which stores passwords in plaintext (to keep it simple) where users can create simple, shitty tests/forms.

I have tried stuff like Wt (C++ Web Toolkit) but can't understand the documentation at all. I've been googling the past few days for some other way to create a simple shitty webpage, preferably in C++, but to no avail.

Can any of you faggots help a poor user out?

I'm a high school dropout who worked at Apple for years. Multiple people in my management chain were dropouts as well. If you can program you don't need a degree.