/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

theguardian.com/uk-news/2017/oct/24/briton-who-fought-isis-killed-in-raqqa-a-week-after-city-liberated
tldrlegal.com/
github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
en.wikipedia.org/wiki/Entity–component–system
godbolt.org/g/WGeV9m
twitter.com/NSFWRedditGif

Ordered and linear types will save systems programming

Thinking of being one of those fags that streams game dev

public synchronized boolean isTopScore(Score newScore, int limit) {
return !scores.stream()
.sorted(Highscore.BEST_FIRST)
.skip(limit - 1)
.findFirst()
.filter(score -> score.getScore() > newScore.getScore())
.isPresent();
}
Man I love lambdas.

They don't love you

>thread dies after you post
theguardian.com/uk-news/2017/oct/24/briton-who-fought-isis-killed-in-raqqa-a-week-after-city-liberated

>Java

Going to be getting jwt shit running in c tonight

Won't sorted() run a sort every time you have a new score (which sounds very coincidental with you asking for the highest score)?
Why not store a reference to the previous top score and only sort when you present the information in full?
What's limit supposed to be here?
Wouldn't just iterating until you find a score > newScore be simpler/clearer if we're not gonna cache? Less complex parts to consider.
Just thoughts. This is fine.

I'm playing with Gtk3 in C++.
I connected the check_resize() signal to a slot, so whenever my window resizes I can scale some stuff inside it.
mainWindow->signal_check_resize().connect(sigc::mem_fun(*this,&foo2020window::on_resize));
It works, but I think it triggers everytime the Window draws, which makes sense, since the signal is called last to check whether GtkWidget changed size (as far as I understand it) and not when it is resized.
Because of this, it's spamming this warning Gdk-WARNING **: gdk-frame-clock: layout continuously requested, giving up after 4 tries

Anyone here know what signal I can use that only triggers when the Window is actually resized?

any good books about writing code that sends and receives data over a network?

Anime?

>privacy error
virus

Other more general thoughts.
As there's plenty of intermediate values thrown away here (mainly from the iterations happening potentially multiple times). Is there ways of accessing these in languages that promote this kind of paradigm?
For instance, if user just wanted the max score here separate from the rest of the operations you could do conditional moves on every iteration of the sorted loop that's gonna capture the max/min value. Making it next to free to access.

Are these tools generally good enough to figure out they can capture that state or is that just a big hole in the api space that implementers have no way of filling? Due to constraints such as not being provided the next pieces of the call chain which you'd normally see in all imperative languages. Though at a compile level i guess this could be done if they're lax enough and the compilers are smart enough, but that's some tricky stuff.

user you need to provide the context you did before.
>IT guy
It really doesn't belong.

Sup Forums is literally the tech review board, belongs perfectly.

Well, be that as it may he doesn't have anything to do with programming especially.

>boost::asio::ip::tcp::socket socket(io_context);
and there are people laughing about java

senpai, he moved on from his boring life and became a hero.
what's your excuse?

Java looks like that if you leave out your imports.

For some reason sepplesfags are allergic to using declarations though.

I'm all for laughing at C++ but that's not even the real standard.

what would happen if i ran out of integers when needing unique ones?

Assuming we're using u64 then you're in deep need of more memory as well.

Ignoring that you'd have to get more bits. Maybe use two integers as identifiers in combination.
Only increment the second one when you're about to wrap the first one.
Check one, if it matches check the second.

>Won't sorted() run a sort every time you have a new score (which sounds very coincidental with you asking for the highest score)?
True, but the method call is ran asyncronously and very infrequently so it doesn't really matter. I just want to make sure I don't end up in a dirty state where the scoreboard has wrong ordering.
>What's limit supposed to be here?
My scoreboard shows top n scores, the caller wants to know if the new score is good enough to be on that list. So I want to check whether it's better than nth score.

I'm not 100% sure I understood your question correctly, but Java Stream API stores method calls and only executes them when it finds a "gather" instruction (such as findFirst() here), optimizing the intermediate calls as much as possible. If you factor JIT optimization and its runtime analysis on top of that then you'll get pretty good performance. It probably won't beat traditional loops but it gets close enough that the difference becomes insignificant.

Writing an offer for a website maintenance contract to a small client

Under which license should I release my shit?

BSD seems like the best. WTFPL is also alright, but it doesn't seem to cover liability.

>neet

that's a good tip thanks!

MIT or PD or CC-A

what about GPL 2?

>CC-A
>GPL 2

I'm hoping to avoid viral licenses like this.

No problem. But you don't need this. Your software should be long dead before people run into u64 identifier problems. As even if you're just identifying single bytes you've got 18 yottabytes of stuff. And using double identifiers like this is slower than just using one.
See infographic.

tldrlegal.com/

It depends.

If you want businesses to use it/sell it somehow: MIT/GPLv2.

If you want to invite people to collaborate and want no businesses except possibly some all-tech -people startup to use your code: GPLv3

Are all API calls essentially returned as JSON?

for a rest api? pretty much.

Can someone splain it to me?
public:
CCOM_OBJECT() : ref_count(0) {}
~CCOM_OBJECT() {}

I can't read a whole C++ book now.

That's the modern standard.

what are you asking exactly

Thanks.
Why JSON? What's the benefit of it?

>As there's plenty of intermediate values thrown away here
streams doesn't work like that and it's evaluated lazily

you can use the peek method to see that each element will go through every part of the chain before the next element

You can use RPC too.

I'm reading some code and can make vague sense of everything but this part.

It declares one variable? What is this ~ line?

That's a destructor. I guess you're not very familiar with C++, but this function is called when the object is destroyed. The function does nothing.

JSON is the current standard, but there are many alternatives to it such as SOAP or YALM.

It's human-readable, natively supported by javascript and everyone's using it.

It can be

>JSON
>XML
>raw text

what else guys?

It's JavaScript's native object serialization format, and even though you didn't specify, if I can assume you're talking about web REST APIs (among the thousands of kinds of APIs that exist) then those are almost exclusively designed to be called by JS running in a user's browser.

If I knew cpp I wouldn't ask.

JSON is better because it's more lightweight compared to its predecessor, XML. Also a lot more readable and ready to be used by JS applications out of the box.

Compare

{
age: 20,
firstName: John,
lastName: Smith
}


and


John
John
Smith

I'm going to grad school next year, the school I'm going to attend has a course about SICP, and part of the Alg & datastructures is in scheme.
I had actually started reading sicp in my free time, and am about half-way the book.

Should I finish SICP before the semester starts so I have more time to focus on the gigantic amount of Math ? Or stop reading it and spend most of my free time preparing myself for the math in order to avoid getting rekt by it ?

I don't really know what would be the best course of action here. I don't really want to be that giant faggot who acts as a know-it-all nerd because he already learned the material beforehand either. Also, I'm mostly a self-taught ""programmer"", but I have no idea how I can do the same with math, I barely understand anything on wikipedia and the book I bought just shows definitions, proofs and then gives the exercises without any explanation. I don't think I'm smart enough to by reading proofs or formulas as I would by reading source code.

I'm assuming you know what Google is too, yet here you are.

Let me just google "that squiggly thing in C++".

Why are you trying to understand C++ code if you don't even know the basics?

Ordered types are cool

...

How to be good at OOP?
What Technology force you to write OOP?

So I'm working on a project for a client through 9irnuniversity, and i think i want to keep the code private unless he says otherwise. Since got hub can't do that for free, is bitbucket a good alternative, or is it hard to use and not as intuitive as using git? Other alternatives are fine

Java.

What a time to be alive.

>True, but the method call is ran asyncronously and very infrequently so it doesn't really matter.
But you're blocking on it. Making it sequential. Assuming you're not talking about the synchronized keyword on this function. Have no idea what that is.
>dirty state
Well that's trivial. I presume sorted() implies it's aware of when it's been dirtied or not (or it'd just be 'sort'). So it's next to free for you to do a sorted call before just about any operation that requires ordering.
>but Java Stream API stores method calls and only executes them when it finds a "gather" instruction (such as findFirst() here)
Well it's less about that.
It's more that assuming you were looking to sort the array if needed, do an average of scores, and find the minimum and maximum scores a hand typed loop could do all that effectively.
But it's not a hard problem to solve this effectively using this api in theory if you can see future calls before the sequence point (semicolon). Because imagine if instead of findFirst().filter().isPresent() was just getMax().
And we add .getAverage() and .getMin()
So:
scores.stream().sorted(Highscore.BEST_FIRST)
.getMax(outputMax)
.getMin(outputMin)
.getAverage(outputAverage);

Then we can see that the sorted call (which iterates the structure) can be merged with these three for next to nothing because an average can be accumulative. A min and max are both just trivially achieved by checking each value in the sort iteration against another saved value. And if there were no sort we could just do all of them at once.

So I'm wondering what's possible for implementers to express.
The gather as you describe isn't sufficient to do this unless you gather until you've reached the end of the call chain and then do your work.
I doubt a JIT would manage to optimize something like this. It's high level analysis that's not meaningfully metrics based.

btfo

gitlab

Well that sucks. Seems like a rather big oversight. I don't understand how this kind of stuff slips past people unless they consciously ignore it and to me that seems like a very big mistake because it's such an obvious use case. How often do you really just want to know a single thing from a data-structure while willing to iterate? And you'd probably like to be able to deal with the way he wrote the max in a more efficient manner.

i didn't say GPL i said PD which is public domain, the most and best license, the lack of license.

what kind of project ? I want something that force me to write Abstract, Interface, ... a lot.

i prefer xml, i've had bad experiences with custom json markup that huge companies use, making it much more time consuming to decode

wait says it's gj club

Yes it is

Argument status: Destroyed

Games are perfect for inheritance and polymorphism. Anything with MVC teaches you how to split things into classes.

>But you're blocking on it. Making it sequential.
Sorry, I mean't that it's running on another thread which is seperate from my main thread. It won't block anything vital there.
>Assuming you're not talking about the synchronized keyword on this function. Have no idea what that is.
It's same as wrapping the method in synchronized(this) block, it uses the object's intrinsic lock to synchronize all calls to the object. I use it to ensure that the list isn't modified while I access it, the modify methods are synchronized as well.
>I presume sorted() implies it's aware of when it's been dirtied or not (or it'd just be 'sort').
Sorted() creates a sorted stream from the base stream, it doesn't modify the original stream.

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

do you fags often get intimidated by jobs posting?
jesus christ there's so much to know

>Games are perfect for inheritance and polymorphism.

>Games are perfect for inheritance and polymorphism.
Note that you'll also get people telling you not to fall into the trap of using inheritance and polymorphism for game programming. While both are technically true, they're talking about different parts of game programming. Where you need to be careful is if you're building the physics & rendering portions a high-performance 3D engine in C/C++ (cache locality, sepples vtables, etc.) but most people aren't doing that.

Every showed something to someone and having them ask how you did it and you be like completely speechless and unable to describe how you did

>OOP style polymorphism

It's not just a performance issue, it's a code organization issue. It's much easier to use composition (properly) to define game objects instead of an inheritance hierachy, because hierarchies are bad when it comes to adding new things or significantly changing existing things.

don't get a job, do bounties instead

>Games are perfect for inheritance and polymorphism. Anything with MVC teaches you how to split things into classes.

No. Most modern games don't use vanilla OOP, they use component entity systems instead.

en.wikipedia.org/wiki/Entity–component–system

>locks the object
Got it, thanks.
>Sorted() creates a sorted stream from the base stream, it doesn't modify the original stream.
Ah, well that's painful.
I guess none of what we've talked about is all that important then.
>games are perfect for inheritance and polymorphism
Depends on your standards but I guess it's fine if you just want to learn to organize code in problematic environments.

>Games are perfect for inheritance and polymorphism. Anything with MVC teaches you how to split things into classes

Thank man, and is making an android game a good start? i already know java, laravel and i had been thinking to learn android some day.

Eh, depends how much of your game logic you're putting in your engine. I guess the moral is
>understand your tools & use them properly
wow so deep I know

void demo()
{
int arr[4];
int (*ptr)[] = &arr;
}
sepples is dumb and bad

No, it really isn't.

>How to be good at OOP
don't use it

What are you trying to say.

where?

that C++ is bad because it does not define sensible conversions that C does

I couldn't compile it on gcc or g++

godbolt.org/g/WGeV9m

advanced unix programming

I think the JSON example should be:
{
"age": 20,
"firstName": "John",
"lastName": "Smith"
}

I passed a phone interview about sepples a few days ago and now I have to do a whiteboard interview about sepples in a week.

I don't know sepples. What are some exercises I should do?

what was your phone interview like?

>I don't know sepples.
You're fucked, then. Every organization has a different understanding of what sepples is or what it should look like. Do you know what their guidelines are?

it was the dev team taking turns asking technical questions.

>asking technical questions.

can you post some of the questions?

How the fuck to Java annotations work?
I look at these frameworks like Spring that do fucking everything with annotations, and I don't get how they do what they do.
Can I get a quick example to illustrate how I can use annotations personally? I think I'll come to understand it best if I see what code uses my annotations.

some examples of the (harder) questions?

People appreciate if you share questions.