/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1486600538102.png (1280x720, 619K)

Other urls found in this thread:

github.com/Cloudnaut/AID
en.cppreference.com/w/cpp/memory/gc/declare_reachable
devdocs.io/javascript/statements/for...of
twitter.com/SFWRedditGifs

cleaning up a shit iso-14229 implementation at work

Attached: 1552127653035.jpg (508x592, 72K)

wish I could sleep forever

Attached: 1461926165210.gif (400x225, 361K)

JavaScript? That sounds nice!

Attached: 4d24ff4e6797a37ed79c564579e294c4.jpg (564x957, 56K)

What are some neat projects that I could make as a portfolio?

I WANT TO ăȘかだし KAREN!!!

Working on a hardware independent C driver for the ESP8266 wifi module

github.com/Cloudnaut/AID

>while (!AT_SendPayload(interface, "kekerino ist lolerino")
more like AIDS desu

for(int i = 0; i < sizeof(*arr)/sizeof(arr[0]); ++i)
Simple, clean, elegant

Attached: 1554454127158.gif (256x192, 1.91M)

>C as a first language
No.
This is how you get terrible programmers.
There are more than enough terrible programmers.
Newfag programmers should not be dealing with memory management before they understand the basic abstract fundamentals of programming.
C's syntax may be simple, but actually writing programs in it isn't.

Is taking an OOP Approach with C++ valid or is it considered heresy and will get me burned in front of the church?

Attached: 1541793058250.gif (680x502, 179K)

>sizeof(*arr)/sizeof(arr[0]

Attached: 1512703916256.png (450x443, 102K)

too lazy to larp as le mastermind busy programmer today maybe tomorrow user

depends on what kind of work your looking for
for embedded i'd say
some can implementation according to either iso 11898 or iso 16845
a decent 14229 implementation goes a long way but maybe its not really applicable for a home project
rudimentary os with rate monotonic scheduling (or some offline scheduling), timer (for sleep/delays, etc), semaphores and priority inheritance can benefit you too
or just a hal and some drivers for any arduino/similar soc and peripherals

you fucked it up

Reposting because more people need to know about this makefile technique.

It works like this:

1. %.d : %.c (makes .d fike)
2. %.o : %.c %.d (makes object, triggers rule 1)
3. include $(wildcard $(.d)) (includes .d files built by rule above, only if they exist)

the first time make is invoked, it will build the .o files. the .d files are irrelevant for this run. for subsequent invocations, make will include the .d files and use the rules defined by the compiler instead of the pattern rule.

Is there even such thing as C++ heresy? C++ "supports all paradigms."

Lol, completely forgot I pushed this shit to the branch. Whatever. Enjoy my dummy strings for testing

>Is there even such thing as C++ heresy?
en.cppreference.com/w/cpp/memory/gc/declare_reachable

So simple, clean and elegant that you couldn't even get it right. The absolute state of C koders.

Why should it? It was literally named "C with classes" originally.

Don't get the hate on tracing GC's desu. What is the time complexity of malloc? It actually isn't a trivial operation. But when you have a GC it can be implemented as a linear allocator.

Exactly but people still use C++ as C but with a different name for some fucking reason, just use C if you won't take any advantage of C++

Found out what my issue was. I changed the name of a variable on the RIGHT side of a recipe which left it undef, and for some reason it would fail to acknowledge the pattern on the LEFT side.

meanwhile in C++
for (size_t i = 0; i < size(arr); ++i)

You have to manually declare something as reachable or unreachable? Seems kind of pointless. I guess it might have use in something like a GUI library where components are passed around like a village whore.

>Reachable objects will not be deleted by the garbage collector or considered to be a leak by a leak detector even if all pointers to it are destroyed.
Retard

>size_t
my condolences user

I think it's only for edge cases where there may be times where there's no recognisable pointers to an object, but it is still reachable, for instance in a xor'd doubly linked list, or if you were to use low bits in pointers as flags or something

Because they are retarded.
Properly written modern C++ especially looks nothing like C, even if you don't use OOP.
They are the same people that believe you still have to manually manage memory in C++.
C++ is a flawed language, but many poeple criticize it for the wrong reasons.

It's actually
for (auto &x : arr)

At least actually learn C++ before bragging, you dumb faggots.

>not for (auto &&x: arr)

Nonsense

Meanwhile in C++
for (auto value : arr)
Meanwhile in JS
for (const value of arr)

>of

Attached: 1523386635027.png (645x773, 23K)

Your C++ version copies every element for no reason.

What if you want it to go from 1 to N-1, referencing i-1 at every step?

>you still have to manually manage memory in C++
You do tho unless i missed something

Attached: 64345234414124.jpg (480x458, 42K)

How come?

foreach(var x in arr)

Attached: 1512908765345.png (488x463, 28K)

ok retard
devdocs.io/javascript/statements/for...of

you usually can use classes and objects that do this for you
for example you may hold your dynamic objects inside a vector and then they will be automatically freed when the vector goes out of scope

Many classes like vector manage their own memory. And then you have smart pointers.

for x in xs

Attached: ea0.jpg (640x648, 65K)

That's still management. You still have to worry about object lifetimes.

why the copies? use the correct version from

luajit's ffi library is neat
i can't believe how easy it is to use

management, yes, but not manual management

You have to worry about object lifetimes in garbage collected languages as well, you just have no control over them
I'd rather write a three-line destructor and never think about it again than my program randomly hang because the mexican maid decided she wants to clear the heap now

From a user perspective how is it different than using Java for example? Sure Java has GC, but the way you actually write code is pretty much the same.

I have no idea where else to ask this.
For the past months I've been self studying math to go to my local community college, but a few days ago they updated their CS program to be pic related...
>Liberal Arts
>LIBERAL ARTS with an emphasis in CS
What in the fuck does this mean?
Should I find a new community college?

Attached: what.png (818x628, 29K)

You have to worry about object lifetimes in languages with built in garbage collection too.

If you never de-reference something it will never get cleared from memory. I had a memory leak myself the other day because I was being a bit overzealous and naive with a callback system I was making. Nothing ever got cleared because they remained in the callback chain even if the components were removed from all possibility of giving feedback / being reached by the user.

Not at all. In Java you don't have to worry about what kind of pointer you should pass and when it should be freed. It just happens when it's necessary.

mathematics is a liberal art

So basically like always using shared_ptr?

Even then you must worry about reference cycles.

>stack is freed at the end of blocks, heap is freed when delete is called
This is too complicated
>GC frees memory when Jupiter is in line with Saturn, and the electrons in the stratosphere spun just the right way
Ah, so much simpler and cleaner

But it says "Liberal Arts Degree"
only "with an emphasis in CS"
It used to be completely different on this page. I see "Liberal Arts Degree" and I feel instantly turned off.

reference counting like shared_ptr uses was an old garbage collection strategy but modern GC languages use tracing garbage collection instead.
i don't think it's very easy to mix tracing with manual memory though

c# can do it

The implementation is a bit difefrent, my point was more about how you use it. Memory management in modern c++ really isn't that hard anymore.
Although I still use raw pointers when I know I won't pass them around anyway.

return Review.find({ _id: {$in: this.reviews} }).then((reviews) => {
if (reviews) {
let total = 0
reviews.forEach(review => {
total += review.rating
});
return total / reviews.length;


Brainlet here. How do I actually make this return "total / reviews.length"? I'm probably forgetting something obvious.

IIRC, you can, but you need an idea similar to
the JVM's GC roots (basically things that the Garbage Collector is not eligible to clear in its tracing garbage collection and it handles manually) and managing those manually is a bit of a pain. Java's leveraging language-level features to determine GC roots. I'm sure with all of C++'s features you could probably figure it out, but eh.

Declare total outside of the if block

I spent whole day reading Java The Complete Reference by Herbert Schildt.

GIMP is the worst software I have ever used, and that includes games that crashed before you could play them.

Attached: fuckgimp.jpg (508x592, 90K)

Then what's a conservative art?

give us a review, user

I probably should've explained a bit better. Right now it's returning the promise (I think) as whole. Pic rel is what it's returning. I need it to just return the value inside the promise if that's possible.

Attached: Capture.png (352x240, 13K)

Then don't use a future, or just get the value from the pomise when it's ready.

Attached: 1445666074181.jpg (328x466, 26K)

liberal is from the latin word for freedom
the liberal arts were the shit that
every respectable non-slave member of society was supposed to know -- originally geometry, rhetoric, and philosophy

>when brainlets think having to manually specify to your compiler that you can free/allocate when needed isn't manual management
The absolute state of (((modern))) programmers

As long as the compiler isn't so stupid I have to tell him manually how many bytes to malloc I don't care

It's because of gtk
Every gtk based gui I've ever used was terrible, always in the exact same way.
Then again, I suppose that's to be expected.
A library with documentation so bad it forces Linux man to use C++ is probably going to have fuck all effort put into end user experience.

The compiler isn't trustworthy and neither is your language.

Is there a way to make shared_ptr syntax simpler with macros or something? It should work like normal pointers, but with some new symbol for example
Object $object = new Object()
but the $ itands for a shared pointer.

Just use typedefs.
Also, don't use naked new.

It's so much worse than the interface.

All I wanted to do was copy the letters, move them around, and smooth things. You can't select a region and movie it. You have to cut and paste onto a new layer, and it collapses it back onto the original layer. BUT if you create a new layer after cutting, you can interrupt the paste and merge what you cut into that layer.

By default the layer view is only as big as what you copied the first time, so if you copied another thing to that later, it can't be seen because your view is restricted.

So let's say you have stuff moved. Now I want to smooth the background into a gradient. Too bad can't do shit. Let's try smooth. It destroys your opacity for no fucking reason. Literally no reason to change the opacity, but it does. Only in GIMP 2.9.5 did that add a "no erasing" option, which was already present in GIMP 2.1, but for whatever cocksucking reason they removed it.

And since you can't smooth regions directly, the image still looks like shit.

If you can't do it in preprocessor macros, then make a shell script or something to edit it. If you're on linux you can pipe the file and do a single substitution or pattern match harder. I prefer Perl because although it's more verbose, it's more portable (sort of, I'm sure you could use sed/awk whatever bullshit in the right windows environment)

I suck ass at this shit but you just put 0 effort in.

Attached: 1547658104661.jpg (508x592, 70K)

thanks,

Attached: meme.png (508x592, 363K)

In Rust, this is just
macro_rules! new {
($($t:expr)?) => {{
std::sync::Arc::new($($t)*)
}}
}

#[derive(Debug)]
struct Foo(i32);

fn main() {
let x = new!(Foo(42));
}

Attached: 1551757602196.jpg (514x524, 58K)

renchon a based

in C++ this is just
using std::make_shared;

>It's so much worse than the interface.
I know, that's what I meant.

Let me put it another way.
The only programmers who use gtk are the people who see nothing wrong with it
Imagine the type of person who sees nothing wrong with a library that disrespectful and dismissive of devs and end users.
These are the kind of people who don't fix a significant amount invalid urls in their docs for months despite being notified of it multiple times.
Now imagine them making a GUI application.

GTK isn't just an interface library
It's a philosophy that believes in fucking over everyone.

weird, there's serious color banding on my phone but none on my PC. I don't know how this shit works, I give up.

template
what does the =string mean?

Target defaults to string if not otherwise given.

default parameter
so you can instantiate myclass and it will default to myclass

default template parameters
if you leave the params empty or ignore them the type of Target will be string

std::sharer_ptr is an atomically reference counted pointer that points to heap allocated memory. In Java a reference might be stack allocated if the optimizer realizes the scope can be reduced.

ah so I thought, thank you

Attached: 1452721870946.jpg (1080x1080, 1.24M)

>weeb
>degenerate
I'm not surprised.

should I really ALWAYS be using accessors instead of direct access to a variable? My professor shilled it pretty hard but it doesn't provide any advantage in this particular case.
My program already runs and all using a getter would do is add more lines to the program.

degenerate weeb website.

having getters and setters makes it easier to modify the implementation later without having to change the public interface or modify the calling code
also, it allows you to ensure that your object will only ever hold VALID data by doing all the checking in one central place, so callers don't have to bother with it

however, if you don't plan to modify this class later and if there are no possible dangerous/invalid values for your member variable, making it public is fine

Where?

right here!

Attached: 1452897258902.png (1000x1000, 408K)

Getters/setters are the most brainlet pahjeet tier OOP.
Out of every horrible thing OOP has birthed, I don't think anything gets more poo.
For the love of fuck, don't use them.
It's just a waste of time.

about the only time where they're actually useful is in multithreaded environments, to help deal with mutexes/atomic operations