sorted by: new top controversial old
[-] Ephera@lemmy.ml 15 points 14 hours ago

At first, I thought this was a screenshot from Lemmy and thought what the hell. Then I saw that it's Reddit and all my questions got answered. ¯\_(ツ)_/¯

[-] Ephera@lemmy.ml 2 points 1 day ago

I tried something like that once. Basically, I was trying to create an API with which sysadmins could script deployments. That involves lots of strings, so I was hoping I could avoid the String vs. &str split by making everything &'static str.

And yeah, the problem is that this only really works within one function. If you need to pass a parameter into a function, that function either accepts a &'static reference which makes it impossible to call this function with an owned type or non-static reference, or you make it accept any reference, but then everything below that function has normal borrowing semantics again.

I guess, with the former you could Box::leak() to pass an owned type or non-static reference, with the downside of all your APIs being weird.
Or maybe your prototyping just happens at the top and you're fine with making individual functions accept non-static references. I guess, you'll still have to try it.

Since you're already at the bargaining stage of ~~grief~~ programming, maybe you're aware, but Rc and Arc are the closest you can get to a GC-like feel. These do reference counting, so unlike GC, they can't easily deal with cyclic references, but aside from that, same thing.
Unfortunately, they do still have the same problem with passing them as parameters...

[-] Ephera@lemmy.ml 3 points 1 day ago

Yeah, I don't think that can happen without splitting the whole ecosystem in half. Garbage collection requires a runtime, and tons of the code semantics are also just different between the two, particularly with asynchronous code.

I also imagine that many people wouldn't just leave their particular program in the GC version, but never even bother to learn the ownership/borrowing semantics, even though those largely stop being painful after a few months.

But yeah, I actually don't think it's too bad to have individual parts of the ecosystem using their own memory management strategies.
The two examples that I can think of are ECS for gamedev and signals/reactivity for UI frameworks. Which is what is used in C++ or JavaScript, Kotlin, too. You'd probably still want to use these strategies, even if you've got garbage collection available...

[-] Ephera@lemmy.ml 12 points 1 day ago* (last edited 1 day ago)

How many bugs you encounter is unfortunately not a good metric, because devs will compensate by just thinking harder. The goal is rather to not need to think as hard, which increases productivity and helps out your team members (including your future self).

It took me a few months of working in an immutable-by-default language before I had the epiphany that everything is exactly like it's written down in code (so long as it's not marked as mutable). I don't need to look at each variable and think about whether it might get changed somewhere down the line. A whole section of my brain just switched off that day.

As the other person said, there's also nothing stopping you from using mutability, it's just not the default, because most variables simply don't get mutated, even in C code.
But I would even go so far that Rust is actually making mutability fashionable again. It has introduced various new concepts in this regard, which you won't know from other languages.

For example, you can opt a variable into mutability, make your changes and then opt out of it again.
And if a function wants to modify one of its parameters, you have to explicitly pass a mutable reference, which is visible both in the function signature and where you're calling the function.

But perhaps most importantly, it blocks you from mutating variables that you've passed into a different thread (unless you wrap the value in a mutex or similar).
In most of the immutable languages up until this point, the immutability was achieved by always copying memory when you want to change it, which is insanely inefficient. Rust doesn't need this, by instead requiring that you follow its ownership/borrowing rules.

Edit:
I also don't know what you heard, but this is for example written in Rust: https://bevyengine.org/examples/3d-rendering/bloom-3d/
The code is right below. It uses lots of mutability...

[-] Ephera@lemmy.ml 8 points 1 day ago* (last edited 1 day ago)

It's the "Entity-Component-System architecture", consisting out of:

  • entities, which are basically just IDs to associate different components,
  • components, which are individual data points like the health or the position or the velocity of an entity, and
  • systems, which operate on components to introduce interactivity. For example, you might have a system which looks at all entities with a position and a velocity component, and then it just adds the velocity to the position. Then another system checks for collisions based on the position component and the dimensions component, and then subtracts from the health component when a collision happened.

It's kind of a competing strategy to OOP. It offers better performance and better flexibility, at the cost of being somewhat more abstract and maybe not quite as intuitive. But yeah, those former two advantages make it very popular for simulations / gamedev. Any major game engine has an ECS architecture under the hood, or at least something similar to it.

[-] Ephera@lemmy.ml 52 points 2 days ago

Right. 😅

Apparently, we're on different pages in this regard, but to me these are less functional language features and more just modern language features.

In my not-so-humble opinion, it was never a good idea to make everything mutable by default. It adds so much mental overhead to try to keep track of where your state could be getting modified, especially in multi-threaded scenarios.
We just didn't have the type system expertise and compiler technology to enforce it without runtime overhead. Now that we have that, I don't think any full-fledged programming language should be released with everything mutable by default.

[-] Ephera@lemmy.ml 16 points 2 days ago

The cool kids in systems programming are using Rust now. I have no idea if game devs are using it.

It's not fully there yet for production use, but there is certainly interest:

  • There's Rust bindings for scripting Godot.
  • A game engine is being built in pure Rust, called Bevy. It's still lacking e.g. a GUI editor, but people are already building smaller games with it.
  • And there's a somewhat more established gamedev studio, Embark Studios, which is contributing quite a bit to the Rust gamedev ecosystem. Might know them from the title 'The Finals', which however wasn't yet implemented in Rust.

One thing to note about Rust for gamedev is that it enforces correctness to a degree which makes it cumbersome for prototyping.
Using it with an ECS already alleviates a lot of that pain (by sidestepping Rust's memory management). And I do imagine, much like in C++, that more and more abstractions will be built on top of it to eventually make it very nice to use.
But yeah, Rust isn't as clear-cut of an upgrade yet, as it is in some other fields.

[-] Ephera@lemmy.ml 30 points 2 days ago

Yeah, it's got some features typically found in functional languages, like first-class functions (being able to pass around functions like values) and various list functions, e.g. .map(), .filter() etc., but the basic control flow is very much imperative.

[-] Ephera@lemmy.ml 16 points 2 days ago

Iron deficiency...

[-] Ephera@lemmy.ml 1 points 2 days ago

Well, it's still a useful comparison for cities. Good traffic planning brings people into the city center via rail and buses, and then they make sure the city center is walkable.

That way, they can fit the most people into the city center, without it turning into a massive traffic jam.

[-] Ephera@lemmy.ml 3 points 3 days ago* (last edited 3 days ago)

Yep, that is precisely what my terminal does out of the box...

[-] Ephera@lemmy.ml 3 points 3 days ago

Hmm, good idea.

I've been using the "Black on White" theme in Konsole, because that's the only real light theme it has, apart from Solarized.
Well, and apparently for some reason it uses brighter colors for what should be intense colors. Just setting the yellow to a normal yellow already improves it quite a bit.

I guess, my point still kind of stands, like why is there no better light theme included out of the box, but yeah, I should probably look into theming a bit more...

326
submitted 4 months ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml
136
submitted 5 months ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml

Real screenshot from (crappy) personal project...

366
submitted 6 months ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml
165
submitted 6 months ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml
488
submitted 7 months ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml
219
submitted 8 months ago by Ephera@lemmy.ml to c/memes@lemmy.ml
10
submitted 8 months ago by Ephera@lemmy.ml to c/android@lemmy.world

Hi, the default Roboto font is boring me out of my mind and I'd like to change it.

In the past, I've done so by just replacing the font file in the OS, which worked well, but meant that it would reset after every OS update.
I'm considering scripting that with ADB to make it less of a pain, but figured I should ask, if there's a better way.

I'm on LineageOS which has a font styling system, but it only applies to the OS, not the user-installed apps...

198
submitted 8 months ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml
2
submitted 2 years ago by Ephera@lemmy.ml to c/technology@lemmy.ml
4
shudders (lemmy.ml)
submitted 3 years ago by Ephera@lemmy.ml to c/programmerhumor@lemmy.ml
view more: next ›

Ephera

joined 4 years ago