271

On the one side I really like c and c++ because they’re fun and have great performance; they don’t feel like your fighting the language and let me feel sort of creative in the way I do things(compared with something like Rust or Swift).

On the other hand, when weighing one’s feelings against the common good, I guess it’s not really a contest. Plus I suspect a lot of my annoyance with languages like rust stems from not being as familiar with the paradigm. What do you all think?

top 50 comments
sorted by: hot top controversial new old
[-] mipadaitu@lemmy.world 73 points 7 months ago

Depends on if you're coding for critical infrastructure (i.e. - electrical grid), or writing a high performance video game that can run on older hardware.

We should absolutely have specific licenses like Civil Engineers do for computer infrastructure that is required for any software written for specific purposes. It would be a nightmare to implement, but at some point, it's going to be needed.

[-] SorteKanin@feddit.dk 34 points 7 months ago

writing a high performance video game that can run on older hardware

Unless it's some really exotic platform, I'd honestly still say no. Rust has shown that memory safety and performance doesn't have to be a tradeoff. You can have both.

But sure, if whatever you're targeting doesn't have a Rust compiler, then of course you have no choice. But those are extremely rare cases these days I'd say.

[-] themusicman@lemmy.world 27 points 7 months ago

There's always a trade-off. In rust's case, it's slow compile times and comparatively slower prototyping. I still make games in rust, but pretending there's no trade-off involved is wishful thinking

[-] Lmaydev@programming.dev 30 points 7 months ago

They mean a trade off in the resulting application. Compile times mean nothing to the end user.

[-] dgriffith@aussie.zone 14 points 7 months ago

That may be true but if the language is tough to develop with, then those users won't get a product made with that language, they'll get a product made with whatever language is easier / more expedient for the developer. Developer time is money, after all.

load more comments (1 replies)
load more comments (16 replies)
[-] fidodo@lemmy.world 60 points 7 months ago

let me feel sort of creative in the way I do things

🚩

[-] mox@lemmy.sdf.org 51 points 7 months ago

I'm just glad to see the White House listening to people who understand technology for a change.

[-] jkrtn@lemmy.ml 22 points 7 months ago

We need legislators who aren't all literally older than cryptography. If they weren't bought and paid for by billionaires that would be nice too.

[-] parens@programming.dev 10 points 7 months ago

That requires a population willing to vote for such legislators.

[-] demesisx@infosec.pub 21 points 7 months ago* (last edited 7 months ago)

Don’t blame the victims for a sham of a democracy. First-past-the-post (FPTP) is there to prevent anything outside of a two party system where primaries are filled with (fully allowed) election fraud and cheating.

“we could have voluntarily decided that, Look, we’re gonna go into back rooms like they used to and smoke cigars and pick the candidate that way. That’s not the way it was done. But they could have. And that would have also been their right.” - DNC Lawyer

load more comments (4 replies)
load more comments (5 replies)
load more comments (10 replies)
[-] onlinepersona@programming.dev 35 points 7 months ago* (last edited 7 months ago)

Leaders in Industry Support White House Call to Address Root Cause of Many of the Worst Cyber Attacks

And it's called C/C++. It's gotten so bad that even the friggin' white house has to make a press release about it. Think about it, the place where that majority barely even understand the difference between a file browser and a web browser is telling you to stop using C/C++. Hell, even the creator and maintainers of the language don't know how to make it memory safe. If that isn't a wake up call, then nothing ever will be.

And this isn't the first call! The IEEE also says more clearly: GTFO C/C++.

If you want memory-safe, don't write C/C++. Trying to get that shit memory-safe is a hassle and a half. You're better off learning a language that isn't full of foot-guns, gotchas, and undefined behavior.

CC BY-NC-SA 4.0

[-] abhibeckert@lemmy.world 21 points 7 months ago

~~If you want memory-safe,~~ don’t write C/C++.

Fixed that for you. There's no situation where you want buffer overruns.

[-] cm0002@lemmy.world 22 points 7 months ago

There's no situation where you want buffer overruns.

I want buffer overruns in my game consoles for jailbreaking purposes lmfaoooooo

load more comments (1 replies)
[-] Feathercrown@lemmy.world 10 points 7 months ago

You’re better off learning a language that isn’t full of foot-guns, gotchas, and undefined behavior.

As a JS developer, seeing this quote about C/C++ for a change gives me unbelievable levels of schadenfreude

[-] technom@programming.dev 35 points 7 months ago

they don’t feel like your fighting the language

I really understand what you mean wrt Rust. I really do - I was there once. But it's a phase you grow out of. Not just that - the parts you fight now will eventually become your ally.

and let me feel sort of creative in the way I do things

I had the same experience with C/C++. But as the design grows, you start hitting memory-safety bugs that are difficult to avoid while coding - even after you learn how those bugs arise in the first place. Just a lapse of concentration is enough to introduce such a bug (leaks, use-after-free, deadlocks, races, etc). I've heard that C++ got a bit better after the introduction of smart pointers and other safety features. But, it comes nowhere near the peace of mind you get with garbage collected languages.

That's where Rust's borrow checker and other safety measures kick in. The friction disappears when you acquire system knowledge - concepts of stack, heap, data segment, aliasing, ownership, mutation, etc. These knowledge are essential for C/C++ too. But the difference here is that Rust will actually tell you if you made a mistake. You don't get that with C/C++. The ultimate result is that when a Rust program compiles successfully, it almost always works as you expect it to (barring logical errors). You spend significantly less time debugging or worrying about your program misbehaving at runtime.

The 'friction' in Rust also helps in another way. Sometimes, you genuinely need to find a way out when the compiler complains. That happens when the language is too restrictive and incapable of doing what you need. You use things like unsafe, Rc and Refcell for that. However, most of the time, you can work around the problem that the compiler is indicating. In my experience, such 'workarounds' are actually redesigns or refactors that improve the structure of your code. I find myself designing the code best when I'm using Rust.

load more comments (2 replies)
[-] Faresh@lemmy.ml 20 points 7 months ago

What memory-safe systems programming languages are out there, besides Rust?

load more comments (12 replies)
[-] dohpaz42@lemmy.world 20 points 7 months ago

I’m going to probably be downvoted to Hell, but I disagree wholly that it’s the language’s fault that people can exploit their programs. I’d say it’s experience by the programmer that is at fault, and that’s due to this bootcamp nature of learning programming.

I’d also blame businesses that emphasize quantity over quality, which then gets reflected in academia because schools are teaching to what they believe business wants in a programmer. So they’re just churning out lazy programmers who don’t know any better.

There needs to be an earnest revival of good programming as a whole; regardless of language, but also specifically to language. We also need to stop trying to churn out programmers in the shortest time possible. That’s doing no one any good.

That’s my two cents.

[-] andyburke@fedia.io 24 points 7 months ago

Gently, I would ask you to think about yourself in a future role where you have too little time, and are under too much pressure, and you haven't gotten enough sleep, and you're distracted on this particular day, and you happen to make a mistake, leave out a line, forget to fix a section of code you were experimenting with...

And even if you, a paragon of programming power and virtue, would never find yourself able to be hurt by your tools, you must surely know that mortals have to work with them as well, right?

[-] words_number@programming.dev 24 points 7 months ago

Id say it’s experience by the programmer that is at fault, and that’s due to this bootcamp nature of learning programming.

You are getting downvoted, because this is factually proven wrong by studies and internal analysis of several huge companies (e.g. google/android and microsoft). A huge number of exploitable bugs are preventable using memory safe languages, nowadays even without performance costs (Rust).

Apart from that your point is orthogonal to the point of the post. You can have better trained coders and have them use better, safer technologies.

We could also just train every driver more thoroughly including mental training and meditation to make sure they are more calm and focussed when driving and we maybe wouldn't need seatbelts anymore. But:

  1. Is that a realistic scenario?
  2. Why not use seatbelts anyway, so there's a higher chance of not dying if some driver didn't sleep well that day?
[-] fidodo@lemmy.world 17 points 7 months ago* (last edited 7 months ago)

Even the best programmers are going to make mistakes at times. Saying the solution is to just be perfect all the time is impossible.

[-] Kissaki@programming.dev 15 points 7 months ago* (last edited 7 months ago)

Memory safety issues were a thing even before bootcamps and "bootcamp culture".

Even if you fix expertise, intention, and mindset - the entire workfield environment and it's people - mistakes still happen.

If you can categorically evade mistakes and security and safety issues, why would you not?

[-] technom@programming.dev 13 points 7 months ago* (last edited 7 months ago)

but I disagree wholly that it’s the language’s fault that people can exploit their programs. I’d say it’s experience by the programmer that is at fault, and that’s due to this bootcamp nature of learning programming.

Considering that even the best programmers in the world can't write correct programs with C/C++, it's wrong to absolve those languages of the massive level of memory safety bugs in them. The aforementioned best programmers don't lack the knowledge needed to write correct programs. But programmers are just humans and they make or miss serious bugs that they never intended. Having the computing power to catch such bugs and then not using it is the real mistake here. In fact, I would go one step further and say that it isn't the language's fault either. Such computing power didn't exist when these languages were conceived. Now that it does, the fault lies entirely with the crowd that still insist that there's nothing wrong with these old languages and that these new languages are a fad.

load more comments (12 replies)
[-] fubo@lemmy.world 18 points 7 months ago

Rust does memory-safety in the most manual way possible, by requiring the programmer prove to the compiler that the code is memory-safe. This allows memory-safety with no runtime overhead, but makes the language comparatively difficult to learn and use.

Garbage-collected compiled languages — including Java, Go, Kotlin, Haskell, or Common Lisp — can provide memory-safety while putting the extra work on the runtime rather than on the programmer. This can impose a small performance penalty but typically makes for a language that's much easier on the programmer.

And, of course, in many cases the raw performance of a native-code compiled language is not necessary, and a bytecode interpreter like Python is just fine.

[-] SorteKanin@feddit.dk 28 points 7 months ago

Rust does memory-safety in the most manual way possible

The most manual way is what C does, which is requiring the programmer to check memory safety by themselves.😛

Also will say that outside of some corner cases, Rust is really not that harder than Java or Python. Even in the relatively rare cases that you run into lifetimes, you can usually clone your data (not ideal for performance usually but hey its what the GC language would often do anyway). And reliability is far better in Rust as well so you save a lot of time debugging. Compiles = it works most of the time.

[-] kogasa@programming.dev 24 points 7 months ago

C# dev with reasonable experience with java, python, and rust:

Rust is harder

[-] 520@kbin.social 19 points 7 months ago* (last edited 7 months ago)

The most manual way is what C does, which is requiring the programmer to check memory safety by themselves.😛

The difference is, Rust will throw a tantrum if you do things in an unsafe way. C/C++ won't even check. It'll just chug along.

Rust is really not that harder than Java or Python.

As someone who's done all three, the fuck it isn't.

If you are familiar with C/C++ best practices to any operational level, those things will translate over to Rust quite nicely. If not, that learning curve is going to be fucking ridiculous with all the new concepts you have to juggle that you just don't with either Java or Python.

load more comments (3 replies)
[-] admiralteal@kbin.social 17 points 7 months ago* (last edited 7 months ago)

I like Rust a lot, philosophically and functionally... but it is WAY harder. Undeniably very hard.

Just try and do anything with, say, a linked list. It's mind-boggling how hard it is to make basic things work without just cloning tons of values, using obnoxious patterns like .as_mut(), or having incredibly careful and deliberate patterns of take-ing values, Not to mention the endless use of shit like Boxes that just generates frustrating boilerplate.

I still think it's a good language and valuable to learn/use, and it's incredibly easy to create performant applications in it once you mastered the basics, but christ.

[-] tiredofsametab@kbin.run 12 points 7 months ago* (last edited 7 months ago)

Software engineer for almost two decades at this point, programming off and on since a kid in the late '80s: Rust is harder. It did seem to get better between versions and maybe it's easier now, but definitely harder than a lot of what I've worked in (which ranges Perl, PHP, C, C++, C#, Java, Groovy/Grails, Rust, js, typescript, various flavors of BASIC, and Go (and probably more I'm forgetting now but didn't work with much; I'm excluding bash/batch, DB stored procedures (though I worked on a billing system written almost entirely in them), etc.)

That said, I don't think it's a bad thing and of course working in something makes you faster at it, but I do think it's harder, especially when first learning about (and fighting with) the borrow checker, dealing with lifetimes, etc.

The availability of libraries, frameworks, tools, and documentation can also have a big impact on how long it takes to make something.

[-] abhibeckert@lemmy.world 14 points 7 months ago* (last edited 7 months ago)

A better approach is the one Apple uses with Swift (and before that, Objective-C... though that wasn't memory safe).

In swift the compiler writes virtually all of your memory management code for you, and you can write a bit of code (or annotate things) for rare edge cases where you need memory management to do something other than the default behaviour.

There's no garbage collection, but 99.999% of your code looks exactly like a garbage collected language. And there's no performance penalty either... in fact it tends to be faster because compiler engineers are better at memory management than run of the mill coders.

load more comments (5 replies)
load more comments (1 replies)
[-] Adanisi@lemmy.zip 12 points 7 months ago* (last edited 7 months ago)

I'm going to advocate for C here: the sheer simplicity, fast compile times, and power it gives you means it's not a bad language, even after all these years. Couple that with the fact that everything supports it.

Rust, while I don't actually know how to write it, seems much more difficult to learn, slower to compile, and if you want to do anything with memory, you have to fight the compiler.

And memory bugs are only a subset of bugs that can be exploited in a program. Pretending Rust means no more exploitation is stupid.

[-] Pipoca@lemmy.world 11 points 7 months ago

And memory bugs are only a subset of bugs that can be exploited in a program. Pretending Rust means no more exploitation is stupid.

This is facile.

According to Microsoft, about 70% of security bugs they see are memory safety issues.

Yes: if you introduce memory safety, there's still those 30% of security bugs left. But, well, I'd rather worry about 30% of issues than 100%...

Similarly, I use libraries that eliminate SQL injections unless you really go out of your way.

load more comments (13 replies)
[-] xmunk@sh.itjust.works 12 points 7 months ago

C++ can have excellent performance without ever using a single pointer and avoiding unsafe functions like gets() - this isn't necessarily a judgment on language - it's a judgement on bad programming habits.

Pointers fucking suck, in a modern C++ codebase everything should be pass by value or const/mutable ref. To my preference I'd rather drop mutable refs to force everything to be more functional but whatever.

[-] OsrsNeedsF2P@lemmy.ml 35 points 7 months ago

I mean that's just the problem with C++. There's 17 different ways to do things, 2 are always wrong, 14 are contextual, and 1 is reserved for super special cases

[-] HornyOnMain@kbin.social 16 points 7 months ago

And the one you choose is always the one that's weak to the specific vulnerability you didn't think of!

[-] SorteKanin@feddit.dk 19 points 7 months ago

Working with habits is just not good enough. C++ has far too many footguns to be considered a safe language and there are frankly objectively better modern alternatives that you should use instead, perhaps except if you have a really large legacy code base you can't replace (but even then, consider calling into it via FFI from a safe language).

Even if you tried to actually enforce these habits, you'd just end up inventing a new language and it would be incompatible with previous C++ too.

C++ is not a viable language for the future.

[-] xmunk@sh.itjust.works 10 points 7 months ago

I get kinda bad vibes from this comment and I'd like to explain why...

If somebody said "We're building a point of sale terminal and to make it secure we're going to be using C++" I'd probably have a dumbfounded expression on my face unless they immediately continued with "because there are libraries we can lean on to minimize the amount of code we need to write."

C++ has an extremely mature ecosystem - Qt is essentially it's own language at this point! There are reasons to still consider building in C++ and saying "C++ is not a language for the future" feels dogmatic and cargo culty to me. Algol, Cobol and Fortran still have programming communities and while I agree that C++ is outsized in presence for the danger it presents there are still good reasons to choose it for some specific domains - high performance graphical programs being one of those in particular.

C++ has a plethora of foot guns and you need to be aware of them but when you are they're easy to avoid in fact your quote:

Even if you tried to actually enforce these habits, you'd just end up inventing a new language and it would be incompatible with previous C++ too.Even if you tried to actually enforce these habits, you'd just end up inventing a new language and it would be incompatible with previous C++ too.

Is probably the thing I agree most with - well built C++ isn't incompatible with regular ol' C++ but it feels like a different language... but as a not too old old-man-developer different projects often feel like different languages - each company/project has tools and libraries they use and it'll cause code written in the same language to read really differently... I'm a functionally oriented programmer with a pretty particular style, my C++, Python, Java, PHP, Node and Rust all look nearly the same except for language specific peculiarities.

So yea, discipline is needed and nobody's default choice should be C++ but if you follow best practices your C++ can be quite safe.

... that all said... I fucking hate the concept of definition files being sseparate from code files so I'm not going to use C++ anytime soon.

[-] abhibeckert@lemmy.world 16 points 7 months ago* (last edited 7 months ago)

Pointers suck in C++. In other languages every single variable is a pointer and it works perfectly with no memory bugs and great performance.

Pass by value often uses too much memory. Especially if you have a bunch of simultaneous functions/threads/etc that all need to access the same value at once. You can get away with it when your memory is a few dozen integers, but when you're working with gigabytes of media... you need pointers. Some of the code I work with has values so large they don't even fit in RAM at all, let alone two or three copies of them. Pass by value could mean writing a hundred gigabytes to swap.

load more comments (2 replies)
load more comments (3 replies)
[-] PhlubbaDubba@lemm.ee 10 points 7 months ago

So that's why I've been hearing non-stop crab rave music!

load more comments
view more: next ›
this post was submitted on 26 Feb 2024
271 points (100.0% liked)

Programming

17241 readers
637 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS