/dpt/ - Daily Programming Thread

Real Programmers Edition #4

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

Attached: ritchie.jpg (220x289, 18K)

Other urls found in this thread:

github.com/enfiskutensykkel/ssd-gpu-dma/tree/latency-bench-rewrite
Jow
amazon.com/C-Programming-Modern-Approach-2nd/dp/0393979504
twitter.com/NSFWRedditImage

working through pic related

Attached: 51j2jjQgMRL._SX258_BO1,204,203,200_.jpg (260x326, 18K)

You motherfuckers can't count.

Attached: 1506713229687.jpg (1280x720, 138K)

Help me with this regex.

I want following inputs to match:
## text ##
(tag) text (/tag)

And these input to NOT match:
## text (/tag)
(tag) text ##

Also I want the 'text' content to be captured into single named group in every valid input. Is this possible?

see

What is the visitor pattern?

Attached: Screenshot_2018-07-22_18-42-52.png (841x60, 28K)

Yes

function application

Is there a #define to check if a certain header is available?

RIP Ritchie. Currently on my first day of actually pro/g/ramming, I decided to start with C using K&R.
Did all the exercises I've encountered so far, toyed around, learned how not to fuck certain things up and such, but it's too early to talk, frankly.
I'm shockingly having fun. I want to see if I reach page 50 by this evening.

In C++... should I basically make everything const?

How the fuck do I into deployment

No matter what I do it never works. I've been programming for almost a year now and I have things I want to deploy to the cloud but it just won't work. I tried spring to google cloud, I tried .net to azure. It's simply not. fucking. working.

How do I learn this shit? I actually have projects on my github that are completed and can be run locally just fine, but I just can't get it deployed.

Attached: pot pain.jpg (894x888, 89K)

make as many things const as you can

const correctness is a good thing ye

>What are you working on, Jow Forums?
Still working on rewriting the latency and bandwidth benchmarking program. I fixed a synchronization issue today, when the number of blocks weren't evenly distributed among threads I would wait on a barrier an uneven amount of times, which obviously wasn't good. This affects the latency measurements somewhat, as I can no longer rely on all threads trying to saturate the disk simultaneously, but it's good enough[tm].

Also cleaned up the output significantly and added aggregated statistics for bandwidth measurements.

github.com/enfiskutensykkel/ssd-gpu-dma/tree/latency-bench-rewrite

this will match the lines
'\(tag\)[[:alnum:][:space:]]*\(/tag)|##[[:alnum:][:space:]]*##

>In C++... should I basically make everything const?
When in doubt, pass a const reference. Even when passing smart pointers. Const references are your friend.

smart pointers are gay because they don't automatically decay to raw pointers

why Jow Forums has no separate board for programming?

i think because it would be dead
not /po/ dead, but pretty dead

>smart pointers are gay because they don't automatically decay to raw pointers
They do for all places that matters, like dereferencing and checking for null.

They don't when you pass them to other functions, which makes them pretty useless.

Some questions here:
1) your country
2)language
3)experience
4)salary

We should riot against the filthy jap until he adds it.

You shouldn't pass raw pointers at all, pass a const reference.

.get() for C compatibility.

i mean programming language ofc

Like most people, I know multiple languages and use multiple languages at work.

>your country
The Netherlands
>language
Java
>experience
5 years relevant experience
>salary
50k per year

That's stupid. If a function does not lengthen an object's lifetime, it does not need to know how that object's lifetime is managed in the parent levels of the call tree. Not to mention that you'll be damaging performance by adding a bunch of unnecessary indirections everywhere.

for the same reason why /sci/ doesn't have a separate math board.

yes I already came up with this, but I want to capture the text into single named group. Problem is, the name of the group needs to be unique

>If a function does not lengthen an object's lifetime, it does not need to know how that object's lifetime is managed in the parent levels of the call tree
That's why you pass a const reference, a reference will not increase the reference count.

>Not to mention that you'll be damaging performance by adding a bunch of unnecessary indirections everywhere.
CONST REFERENCE. REFERENCE.

Do you understand what a reference is?

christ sepplesfags are retarded

dont think so, there are some programming boards at other imageboards, and they arent dead. there are threads for every language, and this is convinient

Please explain to me how you think passing a reference damages performance compared to passing a pointer?

They synthesise down to the exact same assembly.

just use ssh dude

/prog/ used to exist

/prog/ were just a bunch of mental midgets and toilet scrubbers dicking around in Racket and Haskell... wait, that's exactly like /dpt/.. Never mind.

Will he finish TAOCP?

Attached: 1502127132634.jpg (427x505, 44K)

Would someone be so kind as to explain what the FUCK I'm doing wrong here?!

Attached: Learn_JavaScript_Introduction_Codecademy_-_2018-07-22_13.06.28.png (1362x663, 72K)

>relevant
do you have expirience in some other industry?
>50k per year
is this average salary for 5y java programmist in your country?

You're missing a closing parenthesis on the second line.

It actually literally says so in the error message.

First thing I tried. Still incorrect. Got a 0 and this:

"Did you use the Math.floor() method to wrap your random number generator?"

Ok let's try starting the fire, I always wanted to live a revolution

Go here And here Jow Forums.org/feedback

Attached: programming socks.gif (80x70, 35K)

>First thing I tried.
Then you did it wrong.

console.log(Math.floor(Math.random() * 100));

It's my mistake, I misunderstood. I thought you meant passing a reference to the smart pointer.

What would you do if you want the object to be mutable, then?

quit your job
make video games

Okay, apparently the instructions weren't clear. I had to put a SECOND closing parenthesis all the way at the end of the line.

Like that. Thought it had to be at the end of math.random. Fuck, I'm in the intro and already I'm having trouble.

No

>do you have expirience in some other industry?
Nope. I meant to say professional experience.
>is this average salary for 5y java programmist in your country?
It's average for a medior programmer.

You need more than coding to make those. Graphics too, which cost money.

>I thought you meant passing a reference to the smart pointer.
Yes, in the context of smart pointers, yeah, you should always pass const references to them.

void foo(const std::shared_ptr& ptr) // this does NOT increase the reference counter
{
ptr->value = 2; // no level of indirection because the -> operator is overloaded with an inlined function that is optimized away by the compiler
}


>What would you do if you want the object to be mutable, then?
Then you need to make the pointer type const.
typedef std::shared_ptr ConstPointeePtr;

But obviously, preferably you should pass references directly.

void foo(Data& data) // this is preferred
{
data.value = 2;
}

void foo(const std::shared_ptr& ptr)
{
ptr->value = 2;
}

and how much is it compared to the other professions in your country?

>make video games
what a nightmare

no, you should pass shared_ptr by a copy, if you think a const reference is the right way then the shared_ptr wasn't the right answer in the first place

According to the CPB (Bureau for Economic Policy Analysis), the average income in 2018 is 37k.

>you should pass shared_ptr by a copy
No, you shouldn't do that unless you have a particular reason to do so.

>if you think a const reference is the right way then the shared_ptr wasn't the right answer in the first place
I suggest reading Scott Meyers' effective C++ and effective modern C++ and Herb Sutters' exceptional C++.

Oh, so my assumption was right after all.

Yeah, that's a bad thing. These two functions will emit the same assembly.
void foo(const std::shared_ptr& ptr)
{
(*ptr).value = 2;
}

void foo(const std::shared_ptr* ptr)
{
(**ptr).value = 2;
}
Using a reference to a smart pointer means you have an extra level of indirection in your code which is entirely unnecessary, and that's a bad thing for the reasons I described.
An extra indirection can mean an extra cache miss or an extra optimization passed over due to the possibility of aliasing. And no, inlining isn't a silver bullet - that has its own cost in terms of cache utilization and compilation times as well as program organization and becomes impossible after you extract a function pointer.
Also your foo function only works when you use a unique_ptr in the calling function, even though it's entirely irrelevant to the operation of that function. That's a bad thing.

Passing mutable references is a bad thing because it makes the semantics of your program less obvious.
If you see code like foo(bar) then it's expected that bar won't be mutated. Passing by value or by const reference is an implementation detail because it doesn't affect the behavior of the function according to the caller. But passing a mutable reference breaks that rule.

You should only increment a reference count if you need to. If a function is completely nested inside another then there's no point.

>class has 50+ methods for various types of data, each with up to 3 different signatures, e.g. foo(int,double), foo(int,float) and bar(int, double), bar(int, int), etc.
>need to parse a file and call the appropriate methods based on the parsed fields
>i have no type system implemented

what do i do now

Attached: 1531939244967.png (500x312, 283K)

Where do I go about finding basic Javascript exercises? Math, booleans, and the like? What I'm using right now spends too little on those for my liking and jumped straight to variables.

If you care about cache misses, you obviously shouldn't be using shared pointers. This should be fairly obvious and I never argued such.

>Passing mutable references is a bad thing because it makes the semantics of your program less obvious.
I agree that you should use const where it is suitable. I think your argument is highly exaggerated.

void foo(Bar& bar)
{
bar.value = 2;
}


void baz(const Bar& bar)
{
foo(bar); // this will lead to a compilation error
}

Hey guys, what do you think about this API? (error checking and documentation is not yet done but will be).

image.h
typedef struct {
uint8_t r, g, b, a;
} DgImagePixel;

typedef struct {
char *filename;
uint32_t w, h;
DgImagePixel *p;
} DgImage;

DgImage *dgImageNew(DgImage *image);
DgImage *dgImageCopy(const DgImage *src, DgImage *dst);
DgImage *dgImageDel(DgImage *image, bool freeHandle);
DgImage *dgImageRead(const void *p, DgImage *image);
void *dgImageWrite(const DgImage *image, void *p);
DgImage *dgImageLoad(const char *path, DgImage *image);
void dgImageSave(const DgImage *image, const char *path);
DgImage *dgImageLoadFromFile(void *file, bool close, DgImage *image);
void dgImageSaveToFile(const DgImage *image, void *file, bool close);
size_t dgImageSize(const DgImage *image);
void dgImageSet(DgImage *image, uint32_t x, uint32_t y, DgImagePixel p);
DgImagePixel dgImageGet(const DgImage *image, uint32_t x, uint32_t y);

feel like the image header could use one more field to indicate either version or image type

It's useless for me. I need my pixels to be in ABGR order. You expect me to copy all the image data to a custom buffer every time it changes?

You're missing the point on both accounts.

The problem is not that you have an indirection, it's that you have two of them for no reason. Passing a pointer to a pointer (implementationwise) is worthless unless you intend to mutate the pointed-to pointer.

Without context, what will this return?
bool foo()
{
Bar a{10};
Bar b = a;
baz(a);
return a == b;
}
If you avoid mutable references in your code, you don't have to think twice about this.

...either I'm ill equipped for coding or Codeacademy's instructions are poorly written. What the hell am I doing wrong this time?! I see nothing about strings or how to make them.

Attached: Learn_JavaScript_Introduction_Codecademy_-_2018-07-22_13.39.04.png (1362x712, 52K)

Having them decay to raw pointers would make them useless. The whole point of smart pointers is to track copying, which can't happen if they decay.

Why do procedures return DgImage again instead of a success int?
Does dgImageCopy alter the original pointer address?

>use const to make variable
>const variable

oh lord webdevs are so fucking retarded

>variable named entree

Well, what is your variable named?
And what -value- does it have?

>Create a constant variable named entree
>Creates a variable named myName instead
You're ill equipped for life.

c11 generics

The image format is supposed to be used in my game library, and thus does not need generic.

Also, this is not "open any image format" API, the format is as follows:

U32LE: image width
U32LE: image height
U32LE: image filename length
U8v: image filename (used to identify which texture to attach to which model)
{U8 U8 U8 U8} - red, green, blue, alpha, row-major, from bottom to top

Should have explained beforehand.

dgImageCopy allocates and returns completely new image identical to the source.
Should I rename it to dgImageDuplicate or dgImageDeepCopy?

>The problem is not that you have an indirection, it's that you have two of them for no reason. Passing a pointer to a pointer (implementationwise) is worthless unless you intend to mutate the pointed-to pointer.
I literally just fucking said that passing a const reference is preferable:
Are you being deliberately obtuse or are you just born autistic?

>Without context, what will this return?
>If you avoid mutable references in your code, you don't have to think twice about this.
First of all, const references mean shit in "that context", because you may have overloaded the == operator.

Secondly, if you don't intend for a to be mutated and you're already initializing it on declaration, why the fuck wouldn't you do this then:
bool foo()
{
const Bar a{10};
const Bar b = a;
baz(a); // if baz mutates a, then you get a compile error
return a == b;
}

The point of smart pointers is to manage ownership. There are functions which play no role in ownership. It shouldn't be a nuisance to use them when only the caller needs to worry about lifetimes.

I should be able to write this code, because the three functions I call don't play a role in the lifetime of the handle.
void doThis(Handle*);
void doThat(Handle*);
void doTheOther(Handle*);

void doThings(std::unique_ptr h)
{
doThis(h);
doThat(h);
doTheOther(h);
}

Call .get()

Also
>passing a unique_pointer to doThings
This breaks every semantic about ownership.

const variable = 'entree';

Punched that in and it still won't let me pass. The second half is too vague and the above instructions say nothing about strings.

bido gams

Attached: 1519361020763.png (817x443, 34K)

The name of the variable should be entree.

>const entree = "enchiladas"
>const breakfast = "waffles"
>const name = "terry"

My reading comprehension might be shot then. Or as I said, the instructions need to be more clear and specific. Turned up correct, so thank you.

so only unix tards are real programmers huh?

const =

If you allocate memory within the function why do you need the dst argument? What am I missing here?

Just return the new pointer or null on failure.

See, like that? I understood that.

If dst != NULL then dst is assumed to be an unitialized DgImage on the stack.

>Just return the new pointer or null on failure.
Yeah, as I said error checking is not implemented yet but that's exactly how it's going to work.

Could be. I'm passing the instructions without adding a semicolon at the end, which is weird because I'm sure out in the field not putting that in breaks things something fierce. Or it doesn't. I'm very new to this and want to add coding to my resume.

What windowtards would you suggest?

I'm building a config file parser that should have the ability to parse a tree of multiple files. In case of conflict, should I prioritise information in the root or information in a leaf?

Continuing work on my command-line accounting tool / stock tracker written in D.

Attached: Screen Shot 2018-07-22 at 1.55.20 PM.png (1152x1420, 206K)

Can anyone recommend a good "second book" on C? I read "The C Programming Language" by K&R and was impressed by the amount of information they managed to cram into such a short book, but I feel like I'm still missing quite a few things until I can call myself a C developer.

Attached: holy_bible.png (278x359, 32K)

>windows is the only thing beyond the unix world
unix truly is the blub operating system

>2008
>C developer
Are you for real?

>Or as I said, the instructions need to be more clear and specific.
No.
This is on you.
It tells you to create a variable named entree and to set it to the string "Enchiladas".
Instead you named the variable myName and the string "Enchiladas" doesn't even appear anywhere.
Then when it doesn't work it asks if you actually created a variable named entree.

You haven't followed clear and easily understandable instructions.

That's not what I criticized. I said some of the functions parameters and return values are superfluous and contradictory.

You only have two choices: make the functions work on both stack and heap, or just one of the two. Don't know why you would do just one, but I've seen worse. However you don't stick to one strategy but mix them up and thus created a bad api.

IT'S INCONSISTENT

Attached: shouting-370x229.jpg (370x229, 58K)

amazon.com/C-Programming-Modern-Approach-2nd/dp/0393979504

This is an amazing book, you can get it for free from libgen.
It explains well how everything works