/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/dlang/phobos/pull/4878
leetcode.com/problems/arithmetic-slices/
twitter.com/SFWRedditGifs

Say it loud, say it clear, Rust is not welcome here.

RUST IS A MEME

Sup Forums is still pushing the Rust meme?

Is this really what they charge thousands of dollars to learn at the University of Virginia?

That's genuinely surprising.

I know, right? Some people who are helping out are the ones in the chat during his stream presentations.

>September 2013
Nice.

Why is Sup Forums bashing Rust? Just think: RUST IS MEMORY SAFE, if this shit take over the place of C in every field tons and tons of vulnerabilities related to memory problems will disappear!

Imagine living in a world where vulnerabilites related to memory does not exist.

If C++ still hasn't converted C codebases, Rust never will.

Image living in a world where programmers have to hack around the borrow checker.

string literals are memory safe

>Why is Sup Forums bashing Rust?

To be special snowflakes. Although once Rust becomes a bit more proven it's going to take decades to get rid of all the shitty legacy C code in use today.

It's not valid to Rust. If Rust disallows something, there's a good reason for it, usually because it leaves it undefined for the purpose of optimization or because it's never correct to do in the first place.

Because it's different. Same thing happens to Haskell, though Rust is a bit easier to understand so they can attempt to talk about the language itself rather than simply spouting "1 GB/s" and "no jobs" and the like.

Reminder that fully @nogc D has only just begun
github.com/dlang/phobos/pull/4878

updateOnThread(0);
std::vector threads;
for(int i=2; ijoin();
delete(t);
}


>people tell me multithreading is hard
>it's actually easy as fuck

Because the SJWs have taken over Rust.
Therefore its evil, or some stupid us-vs-them shit like that.

But expecting opinions on languages in this thread to ever be valid has always been a mistake. Only Scheme is acceptable.

It's hard when it needs to be scaled up to very large scale concurrent software.

It's easy as fuck because you are creating and destroying threads over and over again which is really inefficient. If you want real performance gains you need to keep the threads around for a long time and have some back and forth communication.

now do that without dynamic memory allocation

something something cucks sjw webdevs steve klabnik is a faggot etc

Also programming in C is totally badass and edge-of-your-seat because your program could segfault and explode in production on someone else's machine at any moment but that never happens of course because Sup Forums is entirely hardcore graybeards who never have mistakes or bugs and if you have an inclincation toward using tools that aren't 40 years old and don't assist you in shooting yourself in the foot then you're basically just a pussy.

C++ isn't strictly memory safe, and people who convert C codebases to C++ usually don't know what the fuck they're doing and make it even worse.

alright Zed Shaw, go back to the bottle.

Being memory safe is cool and all but it's not going to get Rust, adoption. Concentrating on one thing too much harms the rest of the language.

It's a lot easier to go to Rust from C than to C++. Rust is a lot simpler especially with regard to RAII since Rust has no copy/move constructors, has affine types to prevent use-after-move and the like, and doesn't use exceptions for error handling so it's less of an issue if you leak resources in case of a panic because the process will be killed anyways.

Literally no reason other than Mozilla being the one who created it

>but it's not going to get Rust, adoption

Computer security is an absolute joke and it's only going to get worse. There's an enormous need for a modern, natively compiled, memory safe language which isn't dependent on a garbage collector.

>Why is Sup Forums bashing ______

As always: autism

Also, Rust has a nice build system and package manager. C++ is a bloody mess.

RIP modules in C++17
maybe C++20.. maybe.

What happened to C++ modules?
I can't imagine them working well anyway, that kind of things really needs to be native.

nobody actually did anything, it was all plans

>What happened to C++ modules?

The C++ standards committee is extremely conservative and takes a long time to get new features into the standard.

I couldn't imagine them working without heavy header altercations, which is the committees worst nightmare to possibly break anything.

Java is pure.

nobody actually did anything
they don't even have a TS yet

pure poop

HE DOES IT FOR FREE

I think I found a hole in C++ today.

I was creating a struct inside a class, then wanted to forward declare that struct in another header. This doesn't seem possible at all. Am I missing something?

Sup Forums is always right though

Example?

Only time I've had trouble with forward declarations is when i forgot to include them.

I did lua interpreter in C++ using variadic templates and tuples for the parameter lists.
I'm pretty happy with the result. Now I can just type CallLuaFunction("FunctionName", ...any amount of args);

>it doesn't fail to typecheck if he gives the wrong number of args
sad!

>Sup Forums is always right though

Sup Forums isn't even self-consistent

Sup Forums isn't one person.

I am he

Where's the anime profile picture?

It doesn't really matter, it's up to the Lua-scripter to accept the given parameters.
I do however post "did you mean funcName" using the Levenshtein distance, if you mistype a registered function on the C++ side.

Waddup G!

Here

I'm playing with a microcontroller board and would like to make a traffic light controller. I am controlling the traffic lights (3 * three-aspect red/yellow/green lights and 2*two-aspect red/green lights) with two 74F374 shift register ICs. Pic shows the lights and registers.

In the control code I have set up an unsigned int control variable whose bits represent the individual traffic light aspects (total 13 bits used). The high/low bytes of the control variable are shifted bit by bit into the shift registers.

I'd like to create a simple layer of abstraction to the code so that instead of controlling a single red/yellow/green aspect I could just call something like this in my code:
...
Trafficlight_Control(1, GREEN);
Trafficlight_Control(2, YELLOW);
Trafficlight_SetFlash(2, true);
...

where the control functions would accept two ints: the number of traffic light (1...3) and the mode to use or whether to flash or not.

Any advice or hints to get me started?

cute

>AGDG used to be OOP loving Pajeets
>AGDG now hates OOP solely to be contrarian and thinks 400 line switch statements all over the place are okay as long as they're not OOP

you must spread the love and word of FP to agdg

It is on the wrong place

I did mention that if you don't have many variants and are fine with it being a closed, more procedural style system, algebraic data types and pattern matching are fine.

>Rust has a nice build system
It's pretty cancerous tvh.
>and package manager
Languages should never have their own package managers. This is pure evil.

>no programming socks
What do?

Post feet

>It's pretty cancerous tvh.
Elaborate.

>Languages should never have their own package managers. This is pure evil.
Because..?

Because there is already pacman.

you wont like em

And why do you think libraries should be distributed in source form on a per distro basis? This is assuming that we only care about Linux or other operating systems with similar package management.

Linux and other OSwith similar package management are the only relevant OS

Rust locks you into using their special snowflake package manager because you can't just compile individual files without it.

That may be so but what do the language's libraries have to do with the operating system and distro?

Should GitHub not exist and instead people host libraries and applications in source form in distro package repos?

Yes, you can.

That's the way Rust is a safe language

>Should GitHub not exist
Yes.

>That may be so but what do the language's libraries have to do with the operating system and distro?
They must be dropped then.

>C++ isn't strictly memory safe
It's not memory safe at all, but unique_ptr will get you a long way.

C++ is memory safe if you're using Valgrind like you should have learned how in first grade.

Testing is not proving, user.

What are monads?
Dumb way, please

>his favorite language doesn't come bundled with a packet manager, game collection and a web browser

A monad is just a monoid in the category of endofunctors.

Computers are science, not math.

A monad is just a monoid in the category of endofunctors, what's the problem?

Which language does this, faggot?

I don't get what you're asking, if you know how to get the leds to glow why not just do that in your Trafficlight_Control function?
Or maybe I'm not getting something, maybe give a bit more detail?

D WILL RISE

We all agree Rust syntax is horrible. Here's a list of the major problems and how to fix them, and then maybe people will actually use it someday.
1. No block expressions. No implicit returns. Use the fucking keyword.
2. Take the colon out of declaration syntax. remove the question mark operator. Give us a real ternary operator.
3. Take the "!" out of macros. They should look exactly like function calls.
4. Take the pipe bullshit out of closures. Use balanced delimiters.
5. Take out the "::" that sometimes appears when using templates. There is no reason for having this.
6. Fix all the keywords that were renamed for no reason: "match" = "switch," "let" = "auto," "()" = "void," and so on.
7. Replace the stupid "=>" operator with real case labels so IDEs can actually highlight them.
8. Make mutability the default. Use explicit const for immutable variables and references.
9. Put the type before the variable, not after.
10. Remove the pointless "fn" keyword. It's redundant.
11. Put template parameters before the associated declaration instead of mixing them in with a bunch of other stuff where it's impossible to read.
12. Change "self" back to "this" and make it implicit.
13. Struct fields should be defined with the same syntax as declaring variables.
14. Remove "impl Bar for Foo." You should be able to see all the interfaces a type inherits from at the declaration site.
15. Remove "impl Foo." Methods should be defined inside the struct body, or declared there and defined at the top level.
16. Make parentheses mandatory in if/while/for statements. Make braces optional.
17. Bring back the three-part for loop syntax. There are things that simply can't be expressed without it.
18. Make lifetimes completely invisible. They're implicit some of the time. Make them implicit all of the time, or just remove them. If the compiler can't make this work without a bunch of arcane symbols the programmer has to type, there is no point even having the feature.

Test

What are monoids?
What are endofunctors?

>because you can't just compile individual files without it.

You can drive rustc with what ever you wish.


the package manager has nothing to do with fulfilling their requirements for safety.

Python is trash.
Prove me wrong
>protip: you can't

trash gets thrown out. It's more like nuclear waste.

Nice analogy

you think that?

Pretty much

...

monads are basically a programmable semicolon. imagine all of your statements could be evaluated in any order, so if your program was
name = ask_user_for_username()
print(Hello, name)
print(Nice to meet you!)you might get an output like
Nice to meet you!
Hello, null
What's your name?
But so you'd want to do async stuff,

name = ask_user_for_username().whenDone( function(name) { print(Hello, name!).whenDone(function() print(Nice to meet you!)
which is awful, so you write a monad to do the async callback for you:
name = ask_user_for_username(); //

Half of these are wrong.
You're forgetting that Rust through away a few of the fucking retarded ideas that permeate C, and replaced them with much better ML ideas, e.g. 1, 6, 8, 9, 14, 15, 16

in Haskell, the Monad typeclass has the following functions:

return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b

m is the monad, a and b are any type (the function has to exist for any type a and any type b)

one way to think of them for some monads is that return embeds an (a) value as an (m a), and (>>=) can sometimes be thought of as "andThen"

I'm skipping most of these as low quality bait but:

>Remove the pointless "fn" keyword. It's redundant.

Not if they want their grammar to be context-free.

How do you get better at solving things like this?
leetcode.com/problems/arithmetic-slices/

Learning by solving fuckton of this or is there some way of reasoning or some other thing that is required to get better?

JsonArray jsonArray = jsonObject["Groups"].GetArray();

foreach (JsonValue groupValue in jsonArray)
{
JsonObject groupObject = groupValue.GetObject();
SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString());

foreach (JsonValue itemValue in groupObject["Items"].GetArray())
{
JsonObject itemObject = itemValue.GetObject();
group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString()));
foreach (JsonValue contentValue in itemObject["Content"].GetArray())
{
JsonObject contentObject = contentValue.GetObject();
group.Contents.Add(new SampleDataContent(contentObject["UniqueId"].GetString()));
}
}
this.Groups.Add(group);
}
}

So I have this JSON and it has Dictionary inside Dictionary (Groups>Items>Contents)
group.Contents.Add(new SampleDataContent(contentObject["UniqueId"].GetString()));
won't work it just says that Contents is not in group and I totally get that, but I cannot find a way to get into Items and then into Contents. I am totally retarded, can I get some help.

>picture related
The whole json parser

jesus titty fucking christ this is the most hideous, shit piled layered looking code ever, exactly why i stay away from M$.

fuck man, do us all a favor and ditch this shit.

>foreach foreach foreach
just use the list monad

>being this uninformed

Well, that's how it comes from M$, It looks like shit, but it was ready and I want to get over with this shit, all I want is to add another layer, so the JSON itself doesn't look like shit.