/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 7.jpg (460x460, 42K)

Other urls found in this thread:

winestockwebdesign.com/Essays/Lisp_Curse.html
rbt.asia/g/search/subject//dpt//
twitter.com/SFWRedditVideos

Anime is degeneracy.

>js is the most popular programming language
>tools are absolutely shit
explain

Lisp is the worst powerful programming language.

Fuck off, moralfag!

Attached: beyond_good_and_evil.png (639x297, 289K)

are those dunken donuts colors

>shit tools for a shit lang
makes sense

Attached: 1544306842063.jpg (736x780, 75K)

Randomly adding and subtracting 1 until the Assembly error is fixed.

Whoops, forgot to update before posting, so here we go again:

I'm throwing GNU MP at all Project Euler Problems and it works out so far.

Attached: Screenshot_20190214_222056.png (1920x1044, 310K)

So in C++ currently we have conditional noexcept. Sure, sometimes you need to have a function be noexcept only under certain conditions.
And in future versions there's even a TS for conditional explicit. Ok, fine, some parts of the standard library are conditionally explicit. Though it hardly ever gets used it is at least used in some places.

So if we have those, then that must mean we already have conditional const, right?

NOPE

In TWENTY FUCKING EIGHTEEN, we DO NOT have conditional const.
Even though conditional const would be FAR more useful than the above two, NOT ONCE has the standard ever thought "hmm, maybe we should add conditional const"

How many fucking times does the standard library branch on const? How many fucking times have I branched on const in my own code?
TOO MANY FUCKING TIMES TO COUNT
And NOT ONCE has the standard even considered it.
"conditional const? haha we don't need that. Now if you'll excuse me I need to go work on this TS for conditional explicit".

>hur dur useless
No it's not.

Consider this method for an std::variant type:
template
void apply(Fn &&fn) {
// Some possibly recursive complicated shit goes here
fn(value);
}


This applies a function to the current alternative of an std::variant, but that doesn't matter. focus on the fn(value) here.
This method is not callable if the variant is const. Even if fn takes it's parameter by const ref you still can't call apply on a const std::variant. Well yeah of course because we didn't mark the method const. Lets fix that!
template
void apply(Fn &&fn) const {
// Some possibly recursive complicated shit goes here
fn(value);
}

Ok well now we can call apply on a const std::variant. BUT we have another problem now. fn can now only take it's parameter by const. Not taking it by const would result in a compilation error of trying to convert const to non-const.
I.e. it's fucking useless now.

[cont 1/4]

Attached: 1545452495217.jpg (1568x1920, 567K)

There is a way to fix both of these though. multiple ways actually. But currently there is no clean way.
One way of fixing it is by repeating the definition (horrible):
template
void apply(Fn &&fn) const {
// Some possibly recursive complicated shit goes here
fn(value);
}

template
void apply(Fn &&fn) {
// Some possibly recursive complicated shit goes here
fn(value);
}


Or by abusing const_cast (equally horrible, undefined, but at least we're not repeating definitions):
template
void apply(Fn &&fn) const {
const_cast(this)->apply(fn);
}

template
void apply(Fn &&fn) {
// Some possibly recursive complicated shit goes here
fn(value);
}

That last one has it's own problem with it (besides being undefined),
We can call the method on a const object, but there's nothing stopping fn from mutating the value.
This could probably be fixed with a static_assert.

As you can see, there is no clean way to solve this in current C++.
Hence, my proposal:

Like noexcept, we have noexcept(expr) usable in expressions which returns whether the expression is noexcept or not,
and we have noexcept(bool) usable in method declarations to conditionally mark the method as noexcept depending on the value of bool.
You can sometimes see noexcept(noexcept(expr)) syntax being used in method declarations.

So it's trivial to adapt this to const.
We already have a way to determine if an expression is const: is_const
So it would be much more useful if const(expr) returns whether expr is const-correct (doesn't violate constness).
And similarly to noexcept(bool), we'd have const(bool) in method declarations to conditionally mark the method as const based on the (constexpr) value of bool.

[cont 2/4]

Attached: 1519450195846.png (474x568, 411K)

what can lisp do that modern mainstream languages cannot? and vice versa

Attached: 1508294837308.png (1680x2160, 2.58M)

And more more thing: we could introduce the construct const(auto, expr) where expr is an optional constexpr expression convertible to bool.
ret foo(params) const(auto, expr) {body}
would be equivalent to
ret foo(params) const {body}
ret foo(params) const(expr) {body}

expr is optional, so
ret foo(params) const(auto) {body}
would be equivalent to just
ret foo(params) const {body}
ret foo(params) {body}

I.e. it emits two const and non-const (or conditionally-const) versions. Useful if your method needs to work with both.

We already abuse this kind of syntax in decltype(auto) so it should be fine.

So putting all that together, we can now solve our problem easily, cleanly, and correctly:
template
void apply(Fn &&fn) const(auto) {
// Some possibly recursive complicated shit goes here
fn(value);
}


>But I need to change the constness of my return value depending on whether this or a template parameter is const
Easy.
On whether this is const:
auto &get() const(auto) {return thing;}

On whether a template parameter is const:
auto &get() const(is_const_v) {return thing;}

Both:
auto &get() const(auto, is_const_v) {return thing;}

The last one isn't all too useful though as far as I can tell.

Automatic return type deduction will correctly reduce const/non-const in each case.
If you really do need to branch on constness, you can combine constexpr if with the above constructs + is_const_v, or just use the traditional way of overloading on const if it results in cleaner code.

I'm fucking telling you, if the standards committee actually did this, it'd clean up so much of the standard library code, my library code, and I'm sure other peoples code too.
There's nothing worse than having to repeat your code, no matter how trivial the code being repeated is.
Convince me why this is a stupid idea. You can't.

[cont 3/4]

Attached: 1549329315438.jpg (1920x1080, 755K)

You do know it's shunned upon to show off your resolutions of project Euler problems, right? You're spoiling the challenges for other people.

And here's another, probably better way to solve our apply problem.
Since the constness of apply really just depends on fn, there's no need to generate two instances of the method per template instantiation:
// Returns true if all possible variant alternatives can be passed in as const
template
constexpr bool takes_all_const(Fn &&fn) {
return (const(fn(declval())) && ...); // C++17 fold-expr + const(expr)
}

template
void apply(Fn &&fn) const(takes_all_const(fn)) {
// Some possibly recursive complicated shit goes here
fn(value);
}


[4/4]

Attached: 1520314231982.jpg (1920x1080, 574K)

>[cont 1/4]
very mad about sepples

Attached: 1544866540991.png (908x435, 179K)

not be useful
winestockwebdesign.com/Essays/Lisp_Curse.html

go blogpost elsewhere

#include
#include

int main()
{
printf("%u\n", (time_t)time * time(NULL));
}
Rate my pseudo-random number generator. It's nearly indistinguishable from pure random noise:
$ for i in {1..1000}; do ./a.out; done >out
$ wc -l out

How do you add to a dictionary in python dynamically?

I drew over the solution and also I don't think you can read all of the code without realising what you're doing and just stop. If you kept on reading you spoiled it for yourself and can go cry somewhere else.

conditional const is retarded, just use a templated free function

the longer you use C++ the more you realise member functions are a terrible idea

Member functions are unavoidable.

lmao pseudo intellectual atheist referencing nietzsche

Have been working on something for maybe 20-30 hours. Pretty much all pieces are done and have worked when I tried them individually, now I just need to put them together and hope that my program doesn't completely shit itself. Which I expect that it will.

Attached: the joy of programming.jpg (496x1122, 204K)

Define dynamically. You want to create a dictionary, like, in a for loop? Or do you want to populate it?

You can do something like:

colors = ["red", "green", "blue", "caucasian", "negro"]
sizes = list(range(4, 11))

dildos = {}
for size in sizes:
for color in colors:
dildos[color] = size

There is no need to use member functions unless a library you're using does.

Ive got a variable x
I want to set x_average in dictionary values to 1.
When I look in the values dictionary I want to see apples_average as one.

don't bother, if he wants to talk about this, he should make a thread on an appropriate board
he's only posting it because he doesn't frequent the thread and so there are no real consequences for him

False.
Virtual methods.

what is it with all these trash tier PRNGs being posted today?

Are harmful. You shouldn't be using inheritance at all.

dynamically typed languages should not exist

>try and look for information on how to create user defined iostreams
>everywhere says it's so hard don't do it
>look at the source code of dlib's vectorstream
what the fuck is wrong with the people who write programming blogs

dynamic typing doesn't actually exist

Clearly you've never actually written any software in C++ before. What do you use for dynamic polymorphism? Fucking structs of function pointers? That's idiotic.

off topic but is there a collection of /dpt/ thread images somewhere? My folder only has like 5 of them

power = work / time

Something like this?
a = ["a", "b", "c"]
d = {x + "_average": 1 for x in a}
>>>>{'a_average': 1, 'b_average': 1, 'c_average': 1}

C++ is the problem here

you don't use dynamic polymorphism
you use static polymorphism

it's invisible static typing

Yeah thanks for confirming you've never written any software before.

Probably not perfect but you can find your way through it:

items = ["apples", "oranges", "dragons", "dildos"]
averages = {}

for item in items:
averages["{}_average".format(item)] = 1

>Clearly you've never actually written any software in C++ before.
What do you consider to be good C++ software?
>What do you use for dynamic polymorphism? Fucking structs of function pointers? That's idiotic.
Works for C. With templates you can cut down the boilerplate tremendously, too.

you dont need dynamic polymorphism.
its more effective to simply rewrite all the previous code for the special use case you may need it for

it seems to me the problem is fucking retards making a big hooplah out of nothing

>trash tier
Please demonstrate a viable attack on this. The unix timestamp is a nice variable seed, and the function pointer is unpredictable each program invocation in a given system.

>Works for C
Because that's the only option C has. And they're worse than virtual methods.

people always do that

fuck people

That's a really, really horrible idea.

idk.
if i want oop i generally bypass c++ and do java or c#

They're explicit and more flexible.

>comming from the person who uses dynamic polymorphism

Attached: stupidest thing ever hank hill.jpg (500x383, 46K)

if they're attractive (and if it's not gay (lesbianism doesn't count))

Didn't know you could use list comprehensions in dictionaries

Please don't engage in programming discussion until after you've progressed past fizzbuzz.

he's right, except you don't need to rewrite it, you write a metaprogram to write it for you

What is the best non-electron non-webshit language for making GUI's? Everything seems like dogshit.

rbt.asia/g/search/subject//dpt//

C++ with Qt

Assembly

Why is it giving me a little square symbol before the integer?
It's supposed to say "Sum = ", what result is, and then the value in asum. And it does that, but it puts this little square before the number. (The vertical number are cut off, it was just printing all the values in the array)

Attached: Untitled.jpg (281x81, 11K)

You can't always know the type statically. If you think you can you haven't done much programming.

>lesbianism doesn't count
good thing I'm trans :3

Thanks user

It's basically taking the output of another prng and multiplying it with some number. you have to create a new process just to get one random number. if functions are aligned, as they often are, your random number will always be divisible by that alignment. on my system for example, the output is always divisible by 16

At least you admit you're trans and not actually a real female.

That represents a non-printable character.

your pointer must be off by a byte

Is there any way to avoid it?

and that's why you write reflection macros or use code generation tools
fuck the committee
metaclasses now

WPF

As a Haskell programmer I can't approve of mutable state

have fun dealing with suicidal depression
if you get lucky some day youll actually follow through with it and stop suffering

Or just use the builtin language facilities. I agree though metaclasses would be better.
>macros
fuck off

As a (((lisp programmer))) I say that that which changes state is also state itself

The absolute state of lisp programmers

Nevermind. I'm an idiot.
forgot to put ,0 after the string value above

imagine programming without changing a state
l.mao

update

Attached: what a disaster.jpg (496x567, 54K)

based
cringe

Reddit is back that way.

You got btfo here

Attached: smug red and blue men.png (439x297, 151K)

>Qt
Into the trash it goes
>Wangblows
Another for the incinerator

I read through and I think I understand, but I have never come across that particular problem yet, so...
Dunno, I haven't felt like I needed conditionally const yet.

I pronounce Qt as 'queue tea' and there is nothing you can do about it.

>linux
you should've said first that you don't want anybody to use your software

here's a more complete video of the engine.

It doesn't have textures yet because it turns out that while doing fast wall texture mapping on the genesis is quite possible, doing it with subpixel accuracy is significantly harder.
My quick hacky texture mapping hit the same fps as the solid color renderer, which suggests a bottleneck elsewhere, probably the transformation and clipping code which is all in C.

Attached: genesis_3d_demo_2m.webm (636x304, 1.6M)

>marcros are bad
they're as prone to abuse as templates but used responsibly they're not as horrible as people make them out to be
they can be very useful for adding additional metaprogramming capabilities beyond what templates can do

although i would fucking love a clang plugin that adds something similar to reflection
i would make one myself but i can't fucking figure out what i need to do to get a plugin to register on windows
the actual examples use a complicated chain of cmake scripts and i don't know where i can find precompiled dlls to look at what symbols they actually export

What's wrong with Qt?

Sepples garbage.

>they're as prone to abuse as templates
This is incredibly false. Templates do not have sanitation issues.

It has other bindings.

Qt isn't trash because of sepples, it's trash because of really old sepples and non standard pre processors & extensions.

You dont know the worth of annotating until you spend a few hours reverse engineering code that you yourself wrote

qt and any big project needs language extensions
you understand what the moc actually does right

>Describe a recursive algorithm to compute the integer part of the base-2 logarithm of n using only addition and integer division.

Can anyone give me a hint with this? I'm not exactly a mathlet, but...
I've been staring at
x = lb n n = 2^x
for like 30 minutes and don't know where to go from here besides setting base case of
n == 1 return 0
and n == 2 return 1

Very false.
Yes.

something like
int x = 0;
int acc = 1;
while (acc < n)
++x, acc += acc;
return n - 1;