/dpt/ - Daily Programming Thread

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

Eheeh

Anyone else here get a sinking feeling in your stomach when you think about programming? School has ruined it for me.

You need to program in fun programming languages, like C.
Programming in code-monkey tier langauges like Java kills all semblance of enjoyment.

No. Programming is fun.

I'd argue that D is more enjoyable than C.

In fact D is probably the most enjoyable language for linear imperative programming.

if you write in sepples, java, or javascript there is no fun for you. at least C is simple even with c11 and most of the other scripting languages haven't become a shitshow.

How much time do you spend here on average?

Eh, depends how much schoolwork is eating into me.

Sepples is fun tho...

How can some one have fun in writing header files

D is garbage. How could you have fun programming in a garbage programming language?

How is D garbage? In comparison to what?

That code is what a Haskellfag can't do simply.
If you can't read Lisp code then the problem is to read for integers at least 5 times, stopping at the first valid integer, and obviously returning it.
It'd be better if you made it n, but you can make it 5 if you don't wanna create an entire new function.
Oops, nevermind you have to, because the IO Monad will fuck your shit up lol.

D is designed extremely poorly.
- Nonsensical standard library
- No target userbase or niche; the language lacks focus
- Simultaneously too high level and too low level. (garbage collected, but doesn't have the niceties of very high level languages)
- Absolutely ass-backwards features that miss the entire point of what they're trying to emulate (see 'lazy')
- Has no compelling reason to use it over anything else
- Designed over 15 years ago, so doesn't have the modern memes that are in programming languages, but doesn't come with the established base that older languages have

>- Nonsensical standard library
It's well structured and the documentation is quite simple, easy to read and follow. I don't have any issue with the standard library and it makes sense to me as a user.
>- No target userbase or niche; the language lacks focus
That's because it's a general purpose programming language, it's not a bad thing. Language that target a specific use cases are not all that useful for general tasks: see vala, V/AHDL, vimscript etc
Although Javascript has gained much more traction than it should have.
>- Simultaneously too high level and too low level. (garbage collected, but doesn't have the niceties of very high level languages)
Metaprogramming allows you to create templates for higher level concepts. D has a good balance between high and higher level niceties while not completely forsaking performance
>- Absolutely ass-backwards features that miss the entire point of what they're trying to emulate (see 'lazy')
'lazy' makes sense to me although I don't see why anyone would actually use lazy --it's just a high level concept to hold hand to the newbies
>- Has no compelling reason to use it over anything else
C++ done right
>- Designed over 15 years ago, so doesn't have the modern memes that are in programming languages, but doesn't come with the established base that older languages have
>modern memes
We don't sell memes

>not even always_inline inlines for some reason
Stop using a busted compiler? People don't generally use these things. I'm aware compilers aren't magic and will make mistakes but theres almost always a sensible reason why it didn't inline. It's wiser to deal with that than to make it a macro.
Using compiler specific attributes is the next step.

Yeah I had that just after school. You just need to unlearn whatever school taught you that makes you feel bad.

Thanks!

Don't listen to him. It isn't the 70s anymore, there's no reason to start with C unless you already know what you're doing. C was designed for computers with literally kilobytes of RAM and even the most poorfag PC these days has orders of magnitude more than that.

There is also nothing wrong with Python. Obviously not as fast as C but it isn't as slow as people say.

Python and basic damages your brain

>memes

Blender is done in Python right? That has rendering/animation.

...

>It's well structured and the documentation is quite simple, easy to read and follow. I don't have any issue with the standard library and it makes sense to me as a user.
I've never really bothered to look too deeply into their standard library, but quite a while ago, some user (probably you, considering we all know there is only a single D user) linked std.algorithm.searching, and it was fucking stupid. All of these weirdly specific functions, which ends up not being useful at all. All of these similarly named functions which actually did very different things. I can guess that the rest of the standard library is designed just as poorly.
Also, std.stdio.
>That's because it's a general purpose programming language
So? It doesn't mean they can't be focused. C is a general purpose programming language, but it focuses extremely heavily on systems programming, and it does an excellent job at it. Lua is general purpose, but it focuses extremely on being easy to embed into other programs, and it became quite popular for it.
>'lazy' makes sense to me
Learn what lazy evaluation actually is. D's 'lazy' is definitely not it; it's a glorified function call.
>C++ done right
C++ is shit to begin with. Why would you base it on that?
>We
Go home, Andrei. Your language is shit and hasn't gained any notoriety despite being over 15 years old. Give up.

Oh.. Well then!

So I find myself using JavaScript for some reason.
Anyways, I need to pass a value by reference into a function. The value is a member of a struct-like object.
The reason I need to do this is because Qt Qml does not support two-way binding.

So, the way I'm going about this right now is
function updateModel(model, field, viewmodel) {
model[field] = viewmodel;
propertiesChanged();
}
//...
updateModel(myStruct, "member1", memberView)

Supposing Qt QML supported two-way binding, I'd just be able to bind the model properties to the viewmodel properties without bothering with this function.

Anyways, the way I'm going about it bothers me. I absolutely fucking hate using strings as types, and using strings to search for properties. It can only be a design flaw that makes static analysis useless.
Is there a better way to do this?

If you look into the "C++" part of it, it all falls under their 'extern/' directory, so blender is even more C than that language breakdown shows.

>some user linked std.algorithm.searching,
>and it was fucking stupid
Okay
>All of these weirdly specific functions, which ends up not being useful at all.
Don't use them. Like lazy evaluation, it's completely pointless if you actually know programming --I never had to use lazy evaluation in my ~7 years of experience. It becomes a problem if you have hundreds upon hundreds of useless abstractions in the standard (like C++) because it becomes hard to find and master them. On the other hand it's almost always a good idea to use modules written in the library. Probably because it has better code than yours, judging by your response pattern you are pretty young.
> is a general purpose programming language, but it focuses extremely heavily on systems programming
C is not only used in systems programming. In fact there are tons of userspace applications written in C. There are more userspace written in C than the number of kernels in the world
>Learn what lazy evaluation actually is
I know what lazy evaluation is, and it is just a glorified function call.
>C++ is shit to begin with
Which is why I said C++ "done right" :)
>Go home, Andrei
I wish I was as good as Andrei. He is an excellent programmer.

How welcoming is the thread to complete noobs? I got an indian to code me a webscraper on VB for excel but the webpage has changed slightly and the scraper doesnt work. I dont know any code and cant see what it is trying to do/where it is getting stuck. Begging someone to have a look. Would probably take 2 seconds if you knew VB

I'll do you one better. This code can return any readable type after up to 5 user inputs. Lets see you write THAT in Lisp.

readFive :: Read a => IO (Maybe a)
readFive = foldr ((= readFive :: IO (Maybe [Int])
[1,2,3,4]
Just [1,2,3,4]
> readFive :: IO (Maybe String)
asdf
"Hello World"
Just "Hello World"
> readFive :: IO (Maybe String)
[1,2,3]
7
5
asdf
3
Nothing

>This code can return any readable type after up to 5 user inputs
? is that supposed to be anything special?

About kotlin. What are the prospects?

>there's no reason to start with C unless you already know what you're doing
The reason I recommend starting with C is so that you will know what the hell you're doing.

>C was designed for computers with literally kilobytes of RAM and even the most poorfag PC these days has orders of magnitude more than that.
And yet a great deal of the software running on your multi-gigabyte systems are written in C or C++. Just because C is useful for low power systems does not mean it is not also useful for high power systems.

>There is also nothing wrong with Python. Obviously not as fast as C but it isn't as slow as people say.
There is nothing wrong with Python for a number of tasks, but it is clearly not the language one should use for CPU and GPU-bound tasks. If you are developing a program that deals with lots of 3D rendering and animation, you should use a faster language.

I'm waiting on your lisp implementation ;)

I'm not the lisp fag but I am interested in your problem, all your program does is read 5 inputs and prints them right?

Python is a terrible language for developing anything remotely complicated. It's a scientific language. It's for scripts. The moment you touch the OOP side of Python, you're going to wish you had terminal cancer instead.

t. guy trying to make a GUI in PyQt5.

>Qt
>Python

More like
>Qt
>Anything else other than C++
lel

QUICKLY! WRITE A FUNCTION TO CHECK FOR EVEN PARITY OF A 32BIT VALUE!

No, the first n lines are mine, into stdin.
The (Just 4) or (Nothing) line is the output of the program.

I'm not saying you're wrong, but I'm required to learn Python for work and this is the most convenient way for me to do it.

As expected, haskellfag doesn't understand the problem.
You're supposed to read at maximum n times.
If it keeps being non integer, then keep reading until the n times read is expired.
Also, I can make my code in one line and digusting, and unreadable.
Nobody can understand your code lol.
(defun read-five (type)
(loop repeat 5 as in = (read)
if (typep in type) collect in))

*ANDs the last bit with 1* sorry for the pseudo code

>You're supposed to read at maximum n times.
that's exactly what is does
>has to pass in the type
oof

...

Linux is written in C. Where is your Python kernel, retard?

Where did he say about writing kernels in python

>readFive :: IO (Maybe type)
lmao

These trashkell fags need to accept their language is deficient garbage.

this

I don't think you know what parity means.

Both lisp and trashkell are utterly disgusting """languages""".

? type annotations are option. Here the type is infered if I try to add 1 to the result:

(fmap.fmap) ((+) 1) test
asdf
5
Just 6

Yes, but doesn't function call overhead apply to literally all languages? I remember reading something by John Carmack, where he writes about the performance merits and when-and-if scenarios of inlining functions in C++.

>in C++
Stopped reading right there.

c h a r ( * ( * x [ 3 ] ) ( ) ) [ 5 ]

Disgusting trash.

If Python was worth anything, there'd be a kernel written with it. What does it say about a modern language when it's worst in every aspect to a "70s" language?

>If Python was worth anything, there'd be a kernel written with it.
Wrong
> it's worst in every aspect to a "70s" language?
Wrong again. And fix your English.

>C is not only used in systems programming. In fact there are tons of userspace applications written in C. There are more userspace written in C than the number of kernels in the world
That is not contrary to what I said.
>I know what lazy evaluation is, and it is just a glorified function call.
No it's not, you fucking idiot.

Thanks for your opinion, Kim.

>No it's not
Prove it.

>That is not contrary to what I said.
So C is not a niche language

what lang do you use

You're not very smart, are you?

A bitwise AND with 1 would be an optimal method to check a parity bit...

Lazy evaluation IS a function call, junior

Your arguments are baseless, as is your strawman. Enjoy your codemonkey language written for the lowest common denominator, with its only merit to speak of being its supposed ease of use.

Thanks, Kim.

This is incorrect.

>Your arguments are baseless
Usefulness of a language is not measured by the fact that kernels are written in it

Well, that's even more sad.

Prove it.

I didn't say C was niche, I said it was focused.

>focused
More userpspace C projects exist than kernels

/dpt/, what is one practical between a promise and a nullary closure? i know they're not necessarily implemented the same way but regardless they really seem like the same thing

"Systems programming" expands beyond just kernels, you know.

i know systems programming too!
ls

Calling lazy evaluation a ``function call'' is a gross oversimplification. While function calls are an essential element in lazy evaluation, it would be asinine to conflate lazy evaluation with a function call.

The core of lazy evaluation is that data is generated only when needed, instead of beforehand. A getter function is not lazy evaluation.
Lazy evaluation allows you to do new things that were previously impossible. Without the concept of lazy evaluation, you wouldn't be able to represent an infinitely long list using the traditional implementation of one.

The most important part of modern implementations of lazy evaluation is a closure that allows you to keep track of state for when you need to use the same function to get new data.

>Check a parity bit
>Still don't know if it's right
Good job

I thought parity went like this? At least this is how my digital logic teacher explained it.
int checkParity(unsigned value32, unsigned parityBit) {
unsigned i, sum;
/* sum every bit of the value*/
for (i = 0, sum = 0; i < 32; i++) {
sum += (value32 >> i) & 1;
}
/* the sum and the parity bit should add to be even since this is even parity. */
return (sum+parityBit)%2 == 0;
}

Keep telling yourself that. Because as it stands, Python is good for:
>ease of use
>easy to use
>good for beginners
>easy for beginners
>"pythonic"
>etc
And don't get me wrong, I don't even know C, only Python. But I know enough Python to know it's a piece of shit.
I mean, it's so convoluted to reverse a ranged object in Python that, e.g.
range(10)
range(9, -1, -1) # reversed
That you actually have people resorted to calling the reversed() function in their code (I see it all the time), like so
reversed(range(10))
and adding a redundant function call. The very same people praising Python for its "ease of use" are too braindead to figure out how to reverse range(). What does that say about the language?

Why is "my IP or IP range blocked" when I try to reply, but when I change what my reply says, I'm magically not blocked anymore?

Well what the fuck do you need a parity for anyway, a single serving is enough for most people (pair-a-tea)

>Keep telling yourself that. Because as it stands
Huh? How is usefulness even remotely related to kernel development?

#include

int even_parity(int32_t i32)
{
int p = 0;
for(int i = 0; i < 32; i++)
{
p = p ^ (i32 & 1);
i32 = i32 >> 1;
}
return p;
}

Cloudflare has some weird filters on it.
For example, you can't post ls (dash)l, with (dash) replaced accordingly.

...

>Implement smart method to do connected component analysis
>Project manager wants us to do it the old fashion way and run through every pixel
Eat a fucking dick.

If it returns 1 then that means it isn't even parity. There has to be a parity bit of 1 for it to have even parity.

doesn't seem to agree. Lazy evaluations are just another abstraction over function calls.

/dpt/ is it possible to programmatically write an arbitrary strength electrical signal to a specific bit in memory?

Use case: I want to write a simple but effective random number generator that works by storing a static volatile int whose bits are all electrically "fuzzy" so that reading them will produce uniformly inconsistent results at the hardware level

Well if you want to check if it's CORRECT, and not just if it's set, just check to make sure the popcount is even. The parity bit is really just a correction bit, forcing the popcount to be even if it isn't.

pub fn has_even_parity(x: i32) -> bool {
let popcount = x.count_ones();
popcount % 2 == 0
}

I bet if you $ grep 'reversed(' * your Python code, there'd be a match.

How come when I pop my circular, it doesn't get modified.
I can just pop it forever.

I'm glad you also know what it means, you moron.

Is it any good?

>How come when I pop my circular, it doesn't get modified.
Dunno, but:
>I can just pop it forever.
This is a desirable property of a circular. But not if you mean you can just pop it forever and get the same result every time. That's a bug.

How does this run under the hood.

Sorry, there are no CPU instructions for doing that on any modern architecture.