/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1407703380370.png (1207x1060, 508K)

Other urls found in this thread:

haskell.fpcomplete.com/syllabus
twitter.com/AnonBabble

Where my ADA boys at?

I've been working with JavaFX to make a gui for my school assignment. I fucking hate this shit

At the gender """"reassignment"""" "surgery" (mutilation) clinic.

Reminder that address & line number is the only information you need out of a segfault. If you need any more you're a failure of a programmer and you should stop programming forever.

This, but unironically

WTF rude, bigot

I wasn't being ironic, dumb nigger.

very rude of you to apply f to yuki

Doesnt help when you get "error at line 1035 of vector.h"

But from stack trace you can get everything

>/dpt/ bragging that they got a tech-related job
>meanwhile I can't even get a shitty min wage job lifting boxes
it's so fucking unfair

Attached: raymoo.png (574x500, 377K)

you're being paid in Jow Forums

Really? Well I was driving my company audi to my 7 figure Fuzzbuzz Engineer job in Switzerland, when my wife Anri Okita asked me "Do people really do that? Just go on /dpt/ and tell lies?"
I still don't know what I've should have said

I need to make a simple Haskell program for a course, any ideas? I know basic Haskell but I'm pretty much a brainlet.

what about a video game aggregator?
that'd be an interesting little project to work on

like a program that can hook up to any random server, figure out what game client it serves, and what it responds to

then it generates a mimicked client and lets the user play the game before not even hearing about ever

like if open it and it finds a warcraft server and generates a mimic of the game for you and you play it

maybe video recording/analysis would help in the process but I don't know

sorry if I sound retarded im a bit intoxicated

a) make an interpreter for a toy language
b) make some kind of web service
Haskell has great libraries for both use cases. Look also into this:
haskell.fpcomplete.com/syllabus

I would have made it this far you are clever, before you he'll get it over with.

I recommend you get that right.

Fuck off, reddit spacer.

thank you

retard

You would literally need to invent a general intelligence for your program.

What about a movie maker software, you tell it what your movie should look like and it makes a movie for you?

If any of you geeks want to give it a try, I can pay you in exposure

?

You mean Rust trannies

>reading some Stourstrup
>"I don't like that the condition in do-while is at the end, it makes it hard to read"

Nigga you wrote it

I started looking at proper web deving last week, and I have no idea which libraries im supposed to use for what, every one I look at has a description like
>Xjsis a feature rich library that allows you to write progressive and modern websites. X is an approachable and incrementally adoptable ecosystem built on top of (list of 5 other libraries with similar descriptions) and focuses on readabity and flexibility with elegant declarative solutions to complex tasks.

I gave up trying to figure out what some of the do, atm it seems bootstrap, react, jquery, axios is the standard, because I could at least figure out what they do.

Stroustrup didn't make C.

>if (con == null) free(con);

Attached: wow anon.jpg (884x574, 78K)

I'm new to C, but not new to the concepts in C. I'm practicing "safe" memory allocation to avoid buffer overflows.

Don't hold back from roasting, but please give honest criticism and advice on where to improve.

1/2

Attached: 2019-03-08-193610_1920x1080_scrot.png (1920x1080, 1.18M)

2/2

Attached: 2019-03-08-193623_1920x1080_scrot.png (1920x1080, 1.16M)

return con;

free(con):
}

Attached: 1422582434631.jpg (768x432, 39K)

>con = malloc(...);
>con = strcat(con, ...);
This is UB

You only need to free a pointer that was malloced. If malloc returns null then you don't need to free null.
Code after a return statement doesn't get executed.
On line 23 you overwrite a malloc'd pointer. The pointer is lost so there's a memory leak.

Huh, never considered that. Thank you.

con never gets freed and for god sake's don't write code with on a transparent editor with that wallpaper in the background

The simple act of reading a string is actually somewhat retarded. The "normal" thing I see in C is fgets with some BUFFER_MAX length. But if it's exceeded the handling is all shitty without fail.

Alternatively people fuck around with loops, but they barely ever properly work or they do something inefficient like run the whole app with one buffer then start the next loop.

Are you compiling with all warnings? Some of the tooling out there should have flagged this.

>screenshots of code

Yeah kill yourself

>open PR a day ago asking for comments on work in progress
>someone else opens a PR the same day
>maintainer comments on other guys PR
>doesn't comment on or mention mine at all

Attached: 1529349034588.png (1000x815, 676K)

How did I do regarding the handling of strings? That is what I'm primarily looking for feedback on.

I just ran straight gcc str.c -o c. Didn't even consider that. Ran again with -Wall -g and got warnings. Thank you.

Attached: IMG_20190308_201435.jpg (4632x3474, 2.09M)

is the other guy ugly and fat?

Attached: 1506326659_preview_unnamed.jpg (900x900, 99K)

did you just take picture of your screen? size_t is %zu by the way.

If you stray out of purely ISO standard C, POSIX C has a lot of useful shit which makes handling strings a lot safer/sane.
getline() is definitely the best way to deal with input line-by-line.

People have found issues but honestly you did as well as anyone else who's new to C with string handling. Best feedback I've got is always use warnings, and you'll find some of this yourself. Try -Wextra and also consider scan-build from clang.

It was you?

I'm the one fapping on ur P(NT)R story.

His github avatar does look weighty I guess, yes.
Oh god you're right.

Attached: lang.png (1000x1000, 135K)

>hey guys! my name is faggot who are you all?
>hehahe
>hi again my name is fagot derrp

Attached: 69b.jpg (1218x1015, 212K)

Lisp is the white man's language.

If you use languages that allow segfaults in 2020 - 1 you're a failure of a programmer and you should stop programming forever.

Attached: stonetoss.png (1000x1000, 190K)

I've got no one else to ask so:
what are these relationships called, so I can search them up online

Attached: class-adapter.jpg (500x161, 22K)

>UML
Please user, just no.

Going by this logic, every single person on Earth is a failure of a programmer then.

i didn't circle the whole diagram bro, just the names of the relationships

The point is that UML is shit and you shouldn't be using it for any purpose.

What do you suggest instead?

That's a triangle user

C++ app development and C++ library development use completely different languages lol

yeah.. but is there another way to understand and remember design patterns?

just program them lol

C: Who are you?

C++: I'm you but stronger

What algorithm should I look at if I want to connect an entire graph consisting of one root node through direct and indirect nodes?
Like say this:
>node A is connected to node B
>node B is connected to node C but C not connected to A
>current program only connects A to B and that's it. No further branches
>all of this is simply just stored in a 2D array with 2 columns specifying a node and its connected child, eg [[A, B], [A, D]]
>want to make it so that it becomes [A, B], [B, C], [A, D]
>so far can only do one specified node and its children but not grandchildren

I hope I made it clear enough

Attached: 1467144319149.jpg (440x660, 75K)

you haven't explained what your criteria for connecting them is

I don't understand what your criteria are

Libraries define an API, application code uses the API.

Who the fuck are you talking about

If you need design patterns it's because your language is garbage. Use a better one.

Noob here, so I'm just running this because I'm confused about segmentation faults in C++:

int x[2]={0,1}
cout

Yes because when you program in a good language, there's no patterns anywhere, it's just random chaos

Segmentation faults only happen if you access memory in page which is not mapped to your process. They're not guaranteed every time you go out of bounds.
Basically you shouldn't expect any particular behaviour if you go out of bounds.

based and red pilled

Attached: 1552048393211.png (1458x1244, 138K)

based gcc
clang trannies BTFO

comfy

>Basically you shouldn't expect any particular behaviour if you go out of bounds.
Well, that doesn't sound so nice... Any tips or good practices on preventing that?

nice

Don't read past the end of your arrays.

>Any tips or good practices on preventing that?
going out of bounds isn't something you do in the normal course of programming, usually it's a bug

Obviously, but I guess there must be common errors and pitfalls that lead to this. What kind of stupid mistakes usually end up in doing that?

std::array and std::vector have the .at() method which checks if an index is in bounds, and throws an exception if it isn't. This has additional runtime overhead.

Outside of that, just don't fuck up. Use standard iteration constructs like range-based for loops and the functions rather than indexing directly.

Reading past the end of your array is the most common one
or other pointer errors like miscasting

The common way that arrays are used, it's hardly an issue.
Like 90% it's
for (size_t i = 0; i < len; ++i) {
// array[i]
}
Otherwise, if you're just accessing the array at arbitrary, just be aware of the assumptions that you're making.

>at arbitrary
at arbitrary indices*

Can those two be passed as constant pointers to a function?

>fucking up array indexing

really guys

>Want to try something different so I figured I see what all the fuss with Lisps are all about
>Try Common Lisp because its supposed the "practical" list that's used in industry
>Gorrilions of different versions
>Pick one and go through multiple flaming hoops to install it
>Forces me to use a fucking dusty old antiquated emacs with slime or some shit
>emacs sucks so bad that I just go with VSCode
>Try the first free book about it, chapter one and already things are crashing/dying without me having any idea whats going on.

>Try Scheme
>Literally just "sudo apt-get install mit-scheme"
>Reading through SICP and everything is going smoothly

Attached: 1551874929857.png (1920x1882, 2.64M)

std::array does not have this problem

Who is this tortured slut

You can get a pointer to the contents of a std::array or std::vector using the .data() method, but the pointer itself knows nothing about how many elements it points to. There's no way to query a bare pointer whether indexing it with a certain index is valid.
The standard way to pass an array to a function is to pass a pointer+size pair. In that case you can just check if the index is less than or equal to the size.

>The standard way to pass an array to a function is to pass a pointer+size pair
Ok, so I just need something like this assuming a 2D array?

foo (double const std::array *something, int a, int b);

Yeah that's basically what I do. By the way, what's the deal with size_t? How is it different from just int?

Well, just void foo(double *something, size_t a, size_t b);
2D arrays are a bit annoying. You should generally just use a 1D array and multiply the index manually.
size_t is a typedef. It's some unsigned signed type which is large enough to represent any size of array. The exact type differs depend on the platform.

>You should generally just use a 1D array and multiply the index manually.
Sounds reasonable enough.

>size_t is a typedef. It's some unsigned signed type which is large enough to represent any size of array. The exact type differs depend on the platform.
I don't get this... what is it supposed to mean?

Your soul

If you're programming in C++ on Linux, int is 32 bits long while long int is 64 bits long. Therefore long unsigned int can be used to represent the size of an array.
If you're programming C++ on Windows, int is 64 bits long. unsigned int is used to represent the size of an array.
If you want to represent the size of an array (or anything that depends on it such as an array index) in a portable fashion you should use size_t, which your compiler automatically typedefs to the right kind of int.

I'm implementing a clipboard for my operating system so I can copy/paste. It's going pretty well although it's kinda stretching the limits of my simple shared memory primitives.

Attached: Screenshot at 2019-03-08 14-20-14.png (1920x1080, 1.02M)

(and ('based) (red ('pill)))

Based. How many hours you spent writing this, how many LoC per day, how many hours per day?

>current program only connects A to B
>>want to make it so that it becomes [A, B], [B, C], [A, D]
Make current program do the same with B to C and A to D as what it does to A to B