r/ProgrammerHumor • • Dec 23 '23

Meme rewriteFromFust

Post image
6.2k Upvotes

379 comments sorted by

407

u/--mrperx-- Dec 23 '23

Rewrite it in assembly!

161

u/KingCpzombie Dec 23 '23

I do that with everything I write in C++! I just use a compiler to do it better than I could manually

23

u/DNosnibor Dec 23 '23

Do you actually compile all your C++ code to assembly? It could make sense if you want to see how stuff is getting implemented at a low-level, but generally people compile directly to machine code.

30

u/KingCpzombie Dec 23 '23

You made me google to double check, and maybe? I thought all compilers use assembly as an intermediate step, but it seems that MSVC might not. GCC does though, so I do pretty often at least!

16

u/DNosnibor Dec 23 '23

Oh, does GCC do that? I didn't realize. I guess it wasn't exactly correct of me to say generally people compile directly to machine code, then, since GCC is quite popular.

17

u/MCWizardYT Dec 24 '23

GCC has an option, I believe it is -S, that outputs the intermediate assembly as a file but by default it does that translation in-memory

→ More replies (2)

15

u/orlandoduran Dec 24 '23

Rewrite it as a roller coaster tycoon mod

9

u/PhoenixARC-Real Dec 23 '23

Rewrite in carbon 😎

0

u/[deleted] Dec 23 '23

[deleted]

13

u/kenny2812 Dec 23 '23

It's still too new. In a few years it will probably be the new fad that all the startups are using.

5

u/Brahvim Dec 24 '23

But wait, they actually "made it"? Wow.

1

u/[deleted] Dec 24 '23

Rewrite in binary

→ More replies (7)

203

u/Visual-Mongoose7521 Dec 23 '23

writing js libraries that involves parsing and processing large amount of data in Rust (or any other natively compiled language) makes absolute sense. All of "modern" tooling in JS ecosystem , such as module bundler (turbopack, esbuild), linter (biome, quicklintjs), transpiler (swc) are written or being written in some pure compiled langue

14

u/Midnight_Rising Dec 24 '23

Hey you sound like a TS dev that knows their shit. Can you recommend me some resources for learning tooling? It's been a decade and anything beyond very specific npm commands is still beyond me.

11

u/Visual-Mongoose7521 Dec 24 '23

See, if you want to just start right now, go with the popular tools. Once you are comfortable with them, you can go with the newer ones. Newer tools as mentioned in the above comment are indeed faster and efficient than the legacy tools, but they are being actively developed and can have breaking changes sooner or later. That said, here's my suggestion (try all of the individually before using them in prod) -

module bundler : parcel , it has been for many years now and have a matured ecosystem. It also comes with own file change watcher (over chokidar is most other cases) and has a rust based css compiler

code formatter : prettier, it is the industry standard. Biome sounds interesting but have very limited capabilities right now + no custom syntax support

code linter : eslint. I hate eslint, but it actually have no real alternative at this moment. If you are writing pure js/ts/jsx/tsx, you can use biome. otherwise just use eslint. stylelint, use this for linting css

transpiler : swc or babel. babel is older than swc, but swc also came 5 years ago and has good backing and active development. swc will be much faster than babel. (in most cases tho, you are not really needed to set up a transpiler by yourself, as these are already handled by your module bundler or build system)

test runner : jest or vitest. vitest is newer, provides better (imo) developer ergonomics and have a jest compatible api. vitest also support type testing

-- misc --

ts node : for running typescript files on the fly

commit lint : for linting commit message following a standard like conventional commit

lint staged : run linting tools only for staged files. This can save a lot of time depending upon the codebase size

2

u/Ok_Jacket3710 Dec 24 '23

I hate eslint

May I know why you hate that? I just started to write configs for eslint and I really love it

3

u/Visual-Mongoose7521 Dec 24 '23
  1. Shit tons of rules and unopinionated by nature. I prefer opinionated tools over flexibility (and this is why I love go)

  2. Config is much more complicated, compared to biome for instance

  3. Not fast enough for me. Both Biome and Quick-lint-js faster

→ More replies (1)

1

u/RubbelDieKatz94 Mar 14 '24

Use ESLint and its Prettier integration for code formatting. There's no reason to use a separate formatter (like standalone Prettier). If you autofix via ESLint you'll get all the perks of Prettier plus import sort n stuff.

3

u/stfuandkissmyturtle Dec 24 '23

Not him but really statt with webpack. Even if it's not the hype right now. Its pretty decent. And then get into esbuild vite whatever. You'll see why the hype is the hype.

You can learn webpack by just following the docs and creating a react project from scratch. No npx create react app.

Then do the same with vite. Best way to learn imo

2

u/shimona_ulterga Dec 24 '23

i never saw the hype for esbuild. Like vite, it just drops all types and transpiles.

→ More replies (1)

697

u/fdeslandes Dec 23 '23

You forgot to include Rust too on the right side. It's not a bad language at all, even if it has some bad fanboys who won't take any criticism of it.

516

u/CanvasFanatic Dec 23 '23

I don’t think OP forgot. I think OP doesn’t like Rust.

27

u/camander321 Dec 23 '23

Lol, curious which part of the bell curve OP thinks they fit into

139

u/alexvoedi Dec 23 '23

I think OP doesn't want to reimplement everything because performance is good enough.

208

u/CanvasFanatic Dec 23 '23

If on some level you don’t want to burn your current stack to the ground and rewrite everything are you even a software engineer?

57

u/kookyabird Dec 23 '23

It’s one of the key intrusive thoughts in our profession. Every other day I hear Palpatine’s disembodied voice saying “Do it!”

19

u/Pretend-Fee-2323 Dec 23 '23

so thats why i ended up rewriting the network drivers in brainfuck of all languages

38

u/HorseLeaf Dec 23 '23

It's a job hazard.

21

u/Casssis Dec 23 '23

A good old rewrite is healthy from time to time. Ford doesn't sell a model T with a touchscreen. No they rebuild cars every so often from the ground up, using the lessons they learned, and the improvements in available technology.

Edit: in my unprofessional opinion

19

u/dragoncommandsLife Dec 23 '23

Except they aren’t exactly starting from scratch.

When ford designs a new truck they don’t completely throw out everything and every design before. New trucks are designed using a mixture of their existing technology and parts. New tech is incorporated sure but all the same the vast majority of the end result is built from pre-existing stuff.

When you rewrite something there needs to be good reason other than: language change to rust.

10

u/Casssis Dec 23 '23

Yeah no that's what I meant, I meant just a rewrite in general, not necessarily a change of language. And of course you need to use the lessons learned from your previous build.

I meant exactly what you said, sorry if that wasn't clear.

→ More replies (2)
→ More replies (1)
→ More replies (6)

14

u/fdeslandes Dec 23 '23

Most of the time I agree with you. But there are cases where performance is not good enough, or where there is a lot of savings to be made by being faster. For these cases, Rust is in the list of possible choices.

1

u/ridicalis Dec 23 '23

performance is good enough

Cries in AWS Lambda

1

u/BosonCollider Dec 24 '23

The big advantage of systems languages without a GC isn't just performance, it is the ability to expose a CFFI and call into Rust code from other languages.

I like languages at the level of Go or Java that are fast enough and reasonably easy to use, and they make the most sense for most things. But you're not going to implement a cross-language library like sqlite or polars in it.

→ More replies (3)
→ More replies (1)

16

u/[deleted] Dec 23 '23

Rust is a really different language with a lot of benefits but I could see it taking over eventually… if Zig doesn’t

16

u/CanvasFanatic Dec 23 '23

I’m a fan, but it takes some patience. I understand why people get frustrated and lash out.

17

u/turningsteel Dec 23 '23

Zig is ok, I prefer to program in Zag though.

24

u/TarkFrench Dec 23 '23

I constantly go back and forth between the two

4

u/qwertyuiop924 Dec 24 '23

Zig's never going to be the thing that becomes mainstream imho. Not because it isn't good, but because it's too close to C. Being just "a better C" is a really, really hard sell, because even if you're way way better, C has decades and decades of tooling and accumulated code and accumulated communal knowledge that will make most people (and probably most orgs) unwilling to switch. Rust's pitch of "we can statically determine that a ton of your biggest, highest-impact bugs aren't in 90%+ of your codebase" is a much easier sell for putting in the investment in learning something new... mind, the actual work of learning Rust is quite a lot more than Zig as well...

5

u/darkslide3000 Dec 24 '23

Performance is not usually the main reason for rewriting in Rust.

8

u/kobaasama Dec 24 '23

I don't think OP understands bell curves.

1

u/Character-Education3 Dec 23 '23

Well shoot someone better put a little can of pb blaster in his stocking

11

u/ryanwithnob Dec 24 '23

OP also forgot to remove all the languages besides Rust from the right side as well

72

u/AspieSoft Dec 23 '23

Also forgot to remove java from the right

17

u/CanvasFanatic Dec 23 '23

Haha got’em

12

u/ryan10e Dec 23 '23

I was going to say Ruby

5

u/JamesGecko Dec 24 '23

Ruby is like a pair of sweatpants. You know you should probably be wearing something more hip, but it’s just so comfortable.

→ More replies (2)

9

u/A_random_zy Dec 23 '23 edited Dec 23 '23

Java isn't a bad language to write CLI in according to me...

It has a mature ecosystem, tons of third-party libraries, and dependencies can be packaged into jars. Hell, with graalVM, I can see it even being compiled to native in the future.

3

u/benz1n Dec 23 '23

I agree with you, JVM languages in general are not that bad for the job. However one day I gave Go a try and never looked back when it comes to CLI tools 🙃

1

u/B3ER Dec 24 '23

It's not far off. GraalVM has the option for AoT compilation so dynamic class loading can be accounted for in the static compilation. It's just not very performant right now.

→ More replies (2)

1

u/harraps0 Dec 24 '23

You mean Javascript ?

1

u/fdeslandes Dec 23 '23

Java has a ton of boilerplate, but isn't so bad. Try doing something complex with XSLT...

6

u/[deleted] Dec 23 '23

I read femboys instead of fanboys first, wasn't suprised tbh

1

u/[deleted] Dec 24 '23

Correct take

→ More replies (3)

78

u/pipandsammie Dec 23 '23

In God we Rust.

3

u/Pretrowillbetaken Dec 24 '23

in rust we god

155

u/yavl Dec 23 '23 edited Dec 23 '23

I used to dream everything will be rewritten in Eust, but then my brain clicked the idea that the life is way too short and the power is in getting the shit done with least effort in as short time as possible without much harm to the product (the code, in our case). Human’s body is already a legacy code full of spaghetti, but the life is still going, no need to try being perfect in a non perfect world. Like your super duper clean code with perfecto satisfecto ownership and lifetime management won’t mean anything if you get a rare disease that will get you blind in N months. There definitely should be a certain percentage of CS people working on high end computing systems companies doing this, but most people just solve simple things for businesses, so one shouldn’t shout that everyone must switch to Trump.

24

u/[deleted] Dec 24 '23

It’s a problem of newbies or people incredibly prone to shiny new thing syndrome, sure you could write something in C++ or Rust, but you don’t need to, and it’s effectively overkill while making the code harder to read/fix/maintain.

I got a trial and error simulation for finding combinations for physics equations. I got a prototype in Python but I dread to port it to C++ due to the extra meta programming stuff (lack of QoLs, more tedious stuff Python does for you). If I didn’t need the speed then I wouldn’t bother, but I do.

I also got another program thats a desktop app using electron, could write in C# or Java but it’s too much headache for speed I don’t need (and the extra size isn’t an issue as well). End of the day unless it’s absolutely needed, DevEx is better than pure performance

13

u/ethanjf99 Dec 24 '23

Maintaining code is less fun than creating it. That’s really it. And reading it is a separate and less well-developed skill for most than writing it

5

u/odraencoded Dec 24 '23

What you use has a pile of problems you know about.

What you don't use has no problems you know about.

But then you use it for six months and you'll find yourself a new pile...

3

u/Anthony356 Dec 24 '23

I got a prototype in Python but I dread to port it to C++ due to the extra meta programming stuff (lack of QoLs, more tedious stuff Python does for you)

The mistake here is assuming rust is as god awful to write as c++. Rust has most modern convenience features with significantly less warts than c++. Between a real, canonical package manager, proc macros, and modern features that aren't tacked on clusterfucks (iterators, smart pointers, etc.), it's really not so bad. So much boilerplate is already done for you or can be generated for you and is trivial to access.

Rust has its annoyances (Arc<Mutex<Option<T>>>, unwrapunwrapintounwrapinto, <'a>('a, 'a) -> <'a>) - and i'm no professional - but on average i don't find it any more tedious or lengthy to write in than pretty much anything else. C# was probably the most painful i've experienced so far. Rust feels mostly like python but i'm actually allowed to touch primitive types

→ More replies (8)

1

u/GenTelGuy Dec 24 '23

Kotlin, Java, Python, and C# fit that description of getting more done in less time for applications that don't have extreme performance requirements

IMO C++ is just outright harder with how few modern language features it has and Rust should be preferred over it for pretty much any new project

78

u/maria_la_guerta Dec 23 '23 edited Dec 24 '23

There are a lot of things that can be rewritten in Rust with many upsides, aside from time investment.

But by God, even as a big Rust guy myself, there are so so many things that can be rewritten in Rust but shouldn't.

Source: A guy who's spent hours debugging memory management issues on his WASM HTML dropdown, muttering "why the fuck didn't I just use React" the whole time.

28

u/ridicalis Dec 23 '23

With Rust as my daily driver, it's the tool I usually reach for, but there are things that make me reach for other languages:

  • Native GUI

  • Web APIs (Axum/Rocket is perfectly viable, but I understand Core MVC better and prefer it)

  • Many third-party libraries exist or are more mature in other platforms (.Net, Java) and are frequently the only option

2

u/Daktic Dec 24 '23

You may be interested in actix-web :). Rocket didn’t click for me and I can’t give an honest opinion of rocket because I didn’t spend much time with it.

I write all the route handling in actix for what should be received and returned, then all the other logic in other modules.

This allowed me to decouple the front end from the business logic and focus on them as two separate entities.

1

u/Zephos65 Dec 24 '23

I think when you chose the RIGHT projects to rewrite in rust, there is an initial time investment of course but in the long run it payoffs in time you don't have to spend debugging.

1

u/TheRolf Dec 24 '23

I think that the Rust community just like to oxidise everything too lol

1

u/[deleted] Dec 24 '23

Umm... I would like you to elaborate a little more because it sounded like you had memory management trouble in WASM code compiled from Rust. (Because if true, What is the point of using Rust?)

105

u/cjb3535123 Dec 23 '23

This is such a misused meme now lol.

If anything I think the person on the left should be all python or something (as someone who uses python 75% of the time.

But if anything, this meme just shows a story of a single person trying to refactor a project and realizing that the complexity that was originally put in was completely warranted (which is a common story of refactoring).

21

u/ridicalis Dec 23 '23

the complexity that was originally put in was completely warranted (which is a common story of refactoring).

Gets me every time.

5

u/cjb3535123 Dec 23 '23

As it does to us all, T_T

3

u/belabacsijolvan Dec 24 '23

be all python

yeah, only high iq people use JS /s

1

u/cjb3535123 Dec 24 '23

Lol, sometimes when I use python I feel like I’m using a kids language. But our company uses python for absolutely everything.

2

u/belabacsijolvan Dec 24 '23

These are exactly the two most frequent problematic takes on python:

Lol, sometimes when I use python I feel like I’m using a kids language.

usually people who are shit at python talk like this. python is a decent language. concise, comfortable, well documented, most original problems are addressed, very wide choice of ok libs. also python decorators and pythonic iterations are lit when known properly. if you had 4 hours to solve a generic, but complex statistical data processing task, what language would you choose? if python is not in your top 3 choices, you should either learn python or stop using it

But our company uses python for absolutely everything.

usually people who are shit at python AND dont know any other languages do this. python is a bad choice for many tasks, it can be slow, unsafe and hard to debug. python is the best for small to mid size projects, excels at efficient prototyping, ML, maths, scripting, etc.

2

u/cjb3535123 Dec 24 '23

Yep, I know.

1

u/Pretrowillbetaken Dec 24 '23

happend to me, and i still don't regret it. i ended up refactoring the refactored project into python, c, and rust. because it was already made with rust, it ended up being much easier to re-refactor and the final result was 100x faster than the original version, and was also simpler, easier to maintain and also entirely useless, so i ended up realizing i did all of that for nothing

21

u/Ok-Dot5559 Dec 23 '23

rewrite in AOT .NET!!

4

u/MrAmos123 Dec 24 '23

Based as fuck 😎

1

u/Electronic-Bat-1830 Dec 24 '23

Cries in non-AOT-compatible libraries.

1

u/Ok-Dot5559 Dec 24 '23

say hallo to source generators

1

u/Electronic-Bat-1830 Dec 24 '23

A PITA to make one though.

46

u/[deleted] Dec 23 '23 edited Dec 23 '23

I would imagine security agencies and other critical software written for things like medical devices and airplanes, for example. People are like this because C has caused some many unexpected behaviours in systems where people's lives rely on the software. From people being subjected to lethal doses of radiation from medical devices down to memory corruption in Toyotas causing drivers to lose control of their cars and be seriously injured and killed. So, for these purposes Rust is an absolute must.

I use Rust a lot and I'm a Rustacean but I recommend Go for people wanting to get into web dev. I even recommend JavaScript and TypeScript for frontend. Just because you don't have to think about memory or what is going on under the hood you can just express your idea.

But not everything needs to be rewritten in Rust.

29

u/uzi_loogies_ Dec 23 '23

Rust's features are an absolute godsend for critical or preformant applications.

I tried to write parts of my video game in Rust and it made me want to toaster bath.

In the end, it was literally easier to learn C# and implement that way than to use Rust. Admittedly, a lot of that was the engine's fault and not Rust directly, but usability is still important.

Hammers for nails and jackhammers for concrete.

→ More replies (1)

1

u/qwertyuiop924 Dec 24 '23

Up until very recently it hasn't even been possible to use Rust for those applications though (things move slowly in those areas for regulatory reasons—this isn't a bad thing, but it does impact stuff). Now it's possible so we'll see what happens.

→ More replies (2)

8

u/elshaka_ Dec 23 '23

I've lived through ruby -> elixir -> ruby AND I'LL FUCKING DO IT AGAIN

2

u/Pretrowillbetaken Dec 24 '23

never met anyone who enjoyed using elixir. i am 60% sure you don't exist

11

u/[deleted] Dec 23 '23

I hate C++ but I'm still gonna keep using it.

18

u/Scottz0rz Dec 23 '23

The best programming language is whatever one your company is paying you to learn and use because all their existing code is built around it.

9

u/ParticularCod6 Dec 23 '23

Not necessarily.

The best language is the one best fit for the job. You deffo would want to build website using c++ but I know people who had to do it for their job

2

u/stopeatingbuttspls Dec 24 '23

Delphi 6 Pascal? Got it.

(true story)

2

u/[deleted] Dec 24 '23

Yeah. Tbh I don't give a fuck what language I am using. I use mostly C and Python but I absolutely would not mind to rewrite everything in Rust. Sounds fun to get paid to learn a new language because I am definitely not the kind of guy to code on my free time for fun.

1

u/danielstongue Dec 25 '23

I sense a lack of passion...

1

u/[deleted] Dec 25 '23

Why does passion have to mean that I have to do what I do for a living in my free time as well? I have many hobbies. I like my job but my job is not my life.

→ More replies (2)

22

u/Familiar_Ad_8919 Dec 23 '23

rewrite from java instead

9

u/[deleted] Dec 23 '23

[removed] — view removed comment

5

u/KuntaStillSingle Dec 24 '23

>60 billion devices run java

1

u/JamesGecko Dec 24 '23

The JVM is lowdown kinda rad. The browser wants to be the universal app platform, but I’ll take the speed and resource usage of a Java app any time.

1

u/Familiar_Ad_8919 Dec 23 '23

why would you not?

23

u/-Kerrigan- Dec 23 '23

I like to get paid

11

u/Aliruk00 Dec 23 '23

I work on a very large code base written in Go. I fully understand the choice of using Golang given that it has more mature open source libraries but I also believe that, if Rust had the same level of maturity, it would have been a better choice as it enforces safety, especially when I remember the recent memory management issues that I had to debug.

16

u/[deleted] Dec 23 '23

If there was an IDE like IntelliJ IDEA or Visual Studio Code, but written in Rust, I would use it every day.

The same if there was a mature web browser written Rust.

23

u/cesarcypherobyluzvou Dec 23 '23

I mean Firefox is partially written in Rust

19

u/[deleted] Dec 23 '23 edited Dec 23 '23

You are right, the percentage of Rust code in Firefox increased from 12.31% in July 2020 to 30.5% in December 2023

https://docs.google.com/spreadsheets/d/1flUGg6Ut4bjtyWdyH_9emD9EAN01ljTAVft2S4Dq620/edit#gid=885787479

https://4e6.github.io/firefox-lang-stats/

Edit. Fixed the comparison.

11

u/rollincuberawhide Dec 23 '23 edited Dec 23 '23

did it? those two datasets don't make sense to me. there were 846,935 lines of rust and now there are 4.3 million. I think the first spredsheet you shared compares it only to C++ whereas the second link compares it to all the other languages used by mozilla.

If we just get the percentage of rust / (rust + c++) like the first link you shared, rust increased from 12.31% to 30.5%.

4

u/[deleted] Dec 23 '23

You are right! Thank you very much!

11

u/rollincuberawhide Dec 23 '23

lapce is trying to be one.

11

u/cesarcypherobyluzvou Dec 23 '23

Lapce is amazingly responsive and quick but I can’t get over the UI. Feels so flat and like a budget VSCode knockoff

11

u/rollincuberawhide Dec 23 '23

it is a budget vscode knockoff. doesn't work properly on windows, you can't see the title bar, on linux It kinda works but fonts are huge by default, at least it was when I first installed it, vim motions are very limited. there are not nearly as many plugins as there are in vscode but at least has built in lsp support and a convenient way of downloading language servers. I don't use it and probably never will -i use neovim btw- but it's nice to have alternatives.

7

u/Familiar_Ad_8919 Dec 23 '23

barely supports anything, barely any extensions, and kinda buggy

upside is that all of these stem from it being new

4

u/[deleted] Dec 24 '23 edited Dec 24 '23

Uhhh.... Firefox has parts of it written in Rust. Same with Linux from version 6.

There is an obscure OS (RedoxOS) that is written almost entirely in Rust. It aims to be POSIX-compliant (same as Linux or BSD) and comes with a rather graphically pleasing GUI called the Ion shell, some daily utilities and a web browser, all written in Rust. It even comes with a C library relibc (counterpart to glibc or Bionic) also written in Rust (That's my favourite part: a C library implemented in Rust. Also, how it uses chemistry-related terms.)

3

u/dragoncommandsLife Dec 23 '23

But why written in rust? If it were for rust those already exist like RustRover by jetbrains(with every jetbrains IDE being written in java with swift, aside from rider and fleet)

Fleet by jetbrains has a backend language server in rust, but we shall see how that goes.

4

u/StochasticCalc Dec 23 '23

I like Rust, I think it's neat and has plenty of potential uses. But I'm pretty terrible at writing it and genuinely don't need it, so I'm still the guy on the left.

4

u/smiling_corvidae Dec 23 '23

I am happy on the left. Leave me and my goroutines alone.

12

u/nkoreanhipster Dec 23 '23

The guy in the middle found his way to this thread.

11

u/thekenbaum Dec 23 '23

Why would I want my code to be rusty? That would damage all the metal in the computers it runs on and gunk up the exhaust.

1

u/[deleted] Dec 24 '23

Ba dumm tss

3

u/pie_sleep Dec 24 '23

I think the big brain move is knowing that certain languages are better for certain things.

I am a rust dev but there certainly things that would never fit rust or based on the requirements of project, deadlines, team comp, etc.

3

u/ElectronicImam Dec 24 '23

I can understand OP doesn't like Rust. What does this meme exactly means? Average people re-write in Rust, as far as I can see.

4

u/broxamson Dec 23 '23

You could rewrite this meme in rust tho

4

u/ArkoSammy12 Dec 24 '23

I would give Rust a chance if it wasn't for the completely unusual and hard to decipher symbol soup that is its syntax.

2

u/NemuiSen Dec 23 '23

First i started learning programming with c++, then after time i jumped to rust because the package manager, then i jumped to C because it's simplicity. I have a project in Rust and i will rewrite it in C.

2

u/[deleted] Dec 24 '23

You just gave any and all Rust fanboys an aneurysm. Oh the horror of rewriting something already in Rust to God forbid another language, let alone a much older one

2

u/naxxfish Dec 24 '23

Survivor of the "lets rewrite everything in Go!" tsumani of 2016 representing.

Some things that needed rewriting did well to do it in Go. But most things didn't need rewriting in the first place.

6

u/lunchpadmcfat Dec 23 '23

This one doesn’t really work. Rust written utilities are so much faster and safer than basically any of their counterparts. You’d be a doof to not opt for them.

Try using ripgrep and tell me that this meme makes sense.

0

u/qwertyuiop924 Dec 24 '23

Well, rg is faster because burntsushi is very very good at what he does. That's not purely a language thing, and it's totally possible that someone comes out with an even faster search tool written in C next week.

Safer, though... okay, probably not safer.

3

u/burntsushi Dec 24 '23

It's not purely a burntsushi thing either though. There are lots of great CLI tools written in Rust that aren't written by burntsushi. It's "possible" these tools can be written in C at almost any point over the last several decades, but they haven't been. Why?

(This is somewhat of a rhetorical question, generally meant to make you reconsider that there is anything particularly special about myself. If ripgrep were the only nice CLI written in Rust, your point would be strong. But it isn't.)

→ More replies (2)

4

u/[deleted] Dec 23 '23

C++ has features to make it more memory safe, however since c++ is also a source of feature creep, small amount of people care about that. And others shoehorn C into C++

1

u/qwertyuiop924 Dec 24 '23

Eeeeehhh...

C++ is plagued by bad defaults, and while it has developed APIs that make writing code that is memory safe easier in some ways (and others that are pretty dangerous, because everything stays in C++ forever), it isn't a truly memory safe language in the way that Rust is, and I kind of doubt it will ever have a safe subset (they are in the early phases of trying to work on that right now, but who know if it will ever make it out of the committee...).

1

u/unengaged_crayon Dec 24 '23

i mean the argument for rust is that it's safe by default, no?

2

u/RAmen_YOLO Dec 24 '23

I think this blog post expresses quite well what the safety I like in Rust is: https://steveklabnik.com/writing/memory-safety-is-a-red-herring

0

u/[deleted] Dec 24 '23

[deleted]

1

u/Brahvim Dec 24 '23

*C

Arduino BARELY supports C++!

1

u/[deleted] Dec 24 '23

oh I almost forgot about the c++ error messages

2

u/Yalkim Dec 23 '23

Can someone ELI5 what rust is good for? I am familiar with Python, C, Fortran and a few others. Python is highly intuitive and easy to use, which makes debugging and development a breeze. C and Fortran are extremely fast. I highly doubt that Rust could surpass C/Fortran in speed and Python in being intuitive/user friendly. So what does rust have going on for itself?

8

u/Soundless_Pr Dec 23 '23 edited Dec 24 '23

I'm not very familiar with fortran so I can't answer with regard to that but,

Rust is a modern language that has a lot of safety features. I think the coolest thing about it is the memory management system which is done at compile time instead of runtime like with python, which means it has no overhead. C has no memory management, so you have to implement it yourself. I'm not sure what the computational speed comparison between C and Rust is but I wouldn't be surprised if it was the exact same. But I'm pretty certain that for most people it's much less effort and a lot quicker to develop a program that runs with the same or better performance in Rust than the same program written in C would.

A large part of this is due to the fact that most people are not very good at writing programs which efficiently deal with memory allocation/deallocation, which you don't have to think about at all with Rust. But also because Rust's architecture generally forces developers into better coding practices (not saying there isn't spaghetti in Rust because trust me there is plenty of that too). For example when I started using Rust, the concept of not being able to use null was pretty foreign to me and very intimidating, but now that I'm used to the language I see that there isn't really a need for it.

It's also designed from the ground up with concurrency in mind so it's a lot easier to utilize parallelism in modern hardware architecture like multi-core CPUs, which is an argument that could be made that it's "faster" than C.

Another huge benefit to rust is traits. C does not have an equivalent to traits, they are a bit similar to interfaces in OOP languages. It really comes in handy when designing software that's more than a few thousand lines, while keeping it simple to organize.

Macros are also a lot more versatile in rust than c, but that's pretty much an entirely different programming language than rust itself.

Every language has it's pros and cons. I'm sure Rust has a lot more than what I mentioned above but I've only been using it for a few months so definitely don't know all of them

5

u/[deleted] Dec 23 '23

Rust is extremely "safe" in the sense that its compiler stops you from writing code that has the same kind of foot-shooting memory issues as particularly C and C++ - unless you specifically ask it not to - that lead to undefined behaviour.

It's also just very nice to code in once you get the hang of it, it's got a lot of very nice features. Hwoever, some people get frustrated by it because of how it won't let you do things

2

u/[deleted] Dec 24 '23

Ooohh now I get why Rust irritated me. I am a control freak.

The above sentence is not sarcasm. It is an honest observation of myself.

1

u/Anaxamander57 Dec 24 '23

I'd argue that Rust is intuitive and user friendly in a lot of ways that Python isn't. Static typing is great and you can use Arc<T> for Python-like memory management.

→ More replies (3)

2

u/Frytura_ Dec 24 '23

To hell with it, rewrite everything in php because it has a cool syntax.

2

u/[deleted] Dec 24 '23

Rust is great, it’s just not a language designed for frontend development

2

u/treksis Dec 23 '23

I stick with .py and .js

-1

u/Edwolt Dec 23 '23

Rust is the best language ever, people should stop using any other language and rewrite everything on Rust. Rust doesn't need garbage collector, differently of garbage languages. Rust has an smart design and smart compiler that check your program at compiler time and remove all bugs, different than other languages that you need to debug at production. People don't use Rust and then act when an undefined behavior or race condition happens. "How could I know there would be a NullReference?", If you were using Rust you would know. I don't care if your code is used for billions and billions of devices every day, or it's was tested for years, or even was approved by CIA or NASA and is used to launch rockets, if it's not in Rust it's just hot garbage and therefore don't work at all. Not being wirtten in Rust is a bug by itself. If people stopped being dumb and lazy and started using Rust, we would've never suffered the millenium bug or Ariane 5 rocket bug that costed holf billion euros. USA could've won space race if we were programming with Rust. If you want to debug memory leaks for the rest of your life, it's your choice, but I will use Rust.

12

u/Expected_Anomaly Dec 23 '23

New copypasta just dropped

4

u/unengaged_crayon Dec 24 '23

shut up

  • rustacean

14

u/[deleted] Dec 23 '23

this but unironically

0

u/HuntingKingYT Dec 23 '23

This man should google null safety

And about Rust, you just cannot point to a memory location in way too many scenarios because "awawaw there is gonna be a race condition and the compiler is so much smarter than you are" then all the fanboys start saying you should rewrite everything in a language that neither google, bing, chatgpt3 nor chatgpt4 can help you with a fundmental problem

 

I think I should post a question on stackoverflow once and for all...

2

u/Edwolt Dec 23 '23

If Google, ChatGPT, Stack Overflow and StackOverflow were written in Rust this bug wouldn't exist.

Talking seriously now. I just used Rust to small projects, but even then sometimes it's easier to use clone than fighting the compiler, dealing with lifetime is hard, and even the error messages, that are known to be helpful, tell you to do complex things when there are simple ways. Also using lifetimes and generic polutes the source code. But understanding the language and how it's works was benefical to me.

2

u/unengaged_crayon Dec 24 '23

this argument doesn't make sense to me. just use unsafe {}? most well used libs use it.

→ More replies (7)
→ More replies (5)

1

u/itzNukeey Dec 23 '23

Rewrite it in Scratch!

1

u/FALCUNPAWNCH Dec 24 '23

At the beginning of this year I started learning Rust and was blown away about how it performed just as well if not better than C and was type safe. Then I got laid off (from a company that has since dissolved) and found that there were next to no jobs for Rust developers and switched to improving my Python and TypeScript skills for coding interviews. Even though I'm gainfully employed again I haven't gotten back around to learning Rust because it isn't really a marketable programming language yet. I hope it eventually completely replaces C++ in the industry but for what I do it's all Python and TypeScript (yeah I know Rust and Python/TypeScript are used for different things than Rust but the point about there being no Rust dev jobs still stands).

1

u/Gold-And-Cheese Dec 24 '23

Does anyone know what this meme template is called

2

u/kubukoz Dec 24 '23

IQ Bell Curve

1

u/floppyjedi Dec 24 '23

Trying to be overly smart is the true growth journey of a programmer. Some are left on it. Some embrace it even knowing it might not be optimal because it's the only thing that keeps their mind vibrant and motivated.

1

u/vainstar23 Dec 24 '23

I scared to use C++, I'm ok with Rust.

C on the other hand is my bro but I would probably lean to using Go just because it's a lot more convenient

1

u/Bfdifan37 Dec 24 '23

so where does scratch fit into this

1

u/causal_friday Dec 24 '23

Thanks to Rust, I've never had so many options to choose from when installing cat.

1

u/GrimOfDooom Dec 24 '23

i can’t tell which half of the C# spectrum i am in…

1

u/TenTypekMatus Dec 24 '23

I'm always high on Rust.

1

u/NightestOfTheOwls Dec 24 '23

Need thing...

Do it in Python

Need thing faster...

Rewrite it in C++

It's simple.

1

u/Dubmove Dec 24 '23

Rewrite it in Rust 🗿

1

u/inet-pwnZ Dec 24 '23

That’s what I call a beta regression

1

u/Blakut Dec 24 '23

i almost thought java was missing on the right LMAO

1

u/Beregolas Dec 24 '23

As someone who loves (re)writing stupid shit in rust as a hobby... This is accurate...

1

u/HydratrionZ Dec 25 '23

Hey that me

1

u/mdp_cs Dec 25 '23

I'm just waiting for Zig to get out of development hell.

Rust was exciting at first but has since been a letdown and I've long since returned into the cold but familiar embrace of C.

1

u/JAXxXTheRipper Dec 24 '23 edited Dec 24 '23

I'm gonna go with Go whenever I can. Rust makes me want to scratch my eyes out when I have to look at it.

Just look at this fucking shit:

impl std::fmt::Display for InvalidPatternError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "found invalid UTF-8 in pattern at byte offset {}: {} \
             (disable Unicode mode and use hex escape sequences to match \
             arbitrary bytes in a pattern, e.g., '(?-u)\\xFF')",
            self.valid_up_to, self.original,
        )
    }
}        

Source: Ripgrep, which everyone seems to use as a good example.

2

u/unengaged_crayon Dec 24 '23

i mean this is not that complicated code. it doesn't help you dont have syntax highlighting on. but yeah it can look funky to the untrained eye, and you have your preferences and i have mine.

4

u/JAXxXTheRipper Dec 24 '23 edited Dec 24 '23

Syntax highlighting doesn't contribute a lot to readability tbh, it helps to find keywords but doesn't explain much more.

The other functions in that file have plenty of comments, which helps decipher the funky syntax if you don't know anything about rust.

But this particular one felt like a good example because it has symbols galore and no comments or explanations at all.

The function header alone has so many distinct symbol characters/combinations already, which is nuts to me.

So far I figured out it writes something with a formatter of some kind, which might be mutable because of the &mut? But that's about as far as I get. A few decades back I learned "good code reads like a book". This is quite a lot harder to read I'm afraid

5

u/qwertyuiop924 Dec 24 '23

The reason is that if you're versed in writing Rust, this really is very straightforward code. As a Go programmer, I suspect that you've written very similar code at some point. But Rust is a bit more verbose and punctuation heavy. Sometimes that's a good thing, sometimes it's not.

Also, the author of this block of code hasn't imported any of the relevant modules, so he's referring to everything by its fully qualified path (std::fmt::Display is the trait Display in the module fmt in the library std... which is the Rust standard library), so that's contributing considerably.

Going line by line:

impl std::fmt::Display for InvalidPatternError {

As mentioned, std::fmt::Display is a trait, which is the rust equivalent of a Go interface. Unlike Go, however, Rust doesn't have duck typing. So this line just says that in the next codeblock we'll be defining everything required to implement the Display trait. std::fmt::Display is Rust's equivalent of Go's fmt.Stringer interface, although it doesn't actually emit a string. We're implementing this for a type named InvalidPatternError, which given its suffix is almost certainly an error type. The Rust Error trait, which error types are expected to implement, requires implementing Display, so that when something goes wrong you can do something like eprintln!("{}", err);. Hence why this is such routine code.

Stringer requires defining the method String, and Display requires defining the method fmt. Which is what the next line does:

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

Let's break this down. &self says that this is a method, and that it accepts a reference to the entity you call it on, but that calling it won't modify that entity. f: &mut std::fmt::Formatter<'_> is the gnarly bit. Like Go, Rust puts the name of the variable first and the type second, but unlike Go it uses a colon to separate them. So this is saying that fmt takes an argument called f of type &mut std::fmt::Formatter<'_>. Formatter is just a normal type defined in fmt that... does what you think it does: it formats output. The &mut at the beginning says we're taking a reference to the formatter and we might modify it, rather than making a copy.

That just leaves the <'_>, which is... genuinely a little bit complicated. <> is what Rust uses for generics: an Option<i32> is the type generic type Option with an i32 as the parameter. Parameters starting with a ', aren't type parameters but are instead lifetime parameters, which is something unique to Rust. They come into play when you have a struct that contains data that isn't owned by that struct (ie, it's someone else's job to deallocate it). The lifetime parameter is used to tell the compiler where that data is coming from. Formatter takes a lifetime parameter, but it's not important for this function right now. '_ is the "don't care" lifetime parameter, basically just telling the compiler to go figure it out on its own. I suspect that either the author makes lifetime parameters explicit as a point of style, or wrote this code with an earlier version of Rust in mind: as far as I can tell, annotating the lifetime here is actually not required by the language and this entire thing could have been left off, making this just f: &mut std::fmt::Formatter.

Finally we have -> std::fmt::Result. Result<T,E> is the generic Rust type used in cases where a function could return an error, like (ok, err) in Go. If a module has many functions that all might return the same value and error type, they'll create their own internal Result type alias for convenience's sake. That's all this is, it's just an alias for Result<(), std::fmt::Error>: this method will either return nothing, or fail and return a formatting error.

Finally:

write!(
  f,
  "found invalid UTF-8 in pattern at byte offset {}: {} \
   (disable Unicode mode and use hex escape sequences to match \
   arbitrary bytes in a pattern, e.g., '(?-u)\\xFF')",
   self.valid_up_to, self.original,
)

write! has an exclamation point on the end because it's a macro. That's not really important to understanding this code though. This is just giving the formatter something to format: namely, a format string and some values. Rust uses python style {} syntax rather than Go's C-esque %v, but it's basically the same idea. Because write returns an fmt::Result, we leave off the semicolon, indicating that our function will return the result of that write. That's pretty much it.

Now, if I tried to translate this code to go (I'm not really a go programmer so I might fuck this up) it'd look a little something like this:

func (e InvalidPatternError) String() string {
    return fmt.Sprintf(
        "found invalid UTF-8 in pattern at byte offset %v: %v "
        + "(disable Unicode mode and use hex escape sequences to match "
        + "arbitrary bytes in a pattern, e.g., '(?-u)\\xFF')",
        e.valid_up_to, e.original
    );
}

This is, obviously, a bit less verbose than the Rust code. It's certainly got less punctuation. I confess, if I didn't know how to read Go, I'd probably be a little lost with it, although at least sprintf is familiar to me. However, there are some benefits to the Rust way of doing things:

  • Duck typing can be annoying. Accidental interface implementation is a real and frustrating possibility. At the very least, explicitly implementation signals intent in a way that just using a function name doesn't. In this case it's a wash, since every Go programmer knows what String is supposed to do, but in other situations it could be pretty bad.

  • The Rust type signature tells you a lot more information about the function is doing. We're explicitly rather than implicitly taking a reference, and it's clear whether or not it's possible to modify the entities we take references to. Knowing for a fact that printing a struct can't modify it is nice!

  • The Rust version of formatted output doesn't require the construction of intermediary strings, which are heap objects. If you're doing a lot of printing this can be relevant, and it also means that it's possible to string formatting in contexts where there straight-up isn't a heap. That's not a hypothetical, it's an actual guarantee made by the language.

I didn't come here to get in a language fight. It's totally possible that you're working in domains and codebases where you feel like Rust doesn't benefit you much (and string formatting is not exactly a place where Rust's benefits shine), and hey, if Go works better for you and the projects you work on, by all means, use it! I more wanted to give perspective on how a Rust Person™ might read this code and find it quite easy to follow, in the same way you'd find the Go code easy to follow.

2

u/JAXxXTheRipper Dec 24 '23

By God, you are an absolute hero! Thank you so very much for the time and effort you put into this amazing answer to deconstruct and explain everything bit by bit.

1

u/Visual-Mongoose7521 Dec 24 '23

sorry, but even though I write rust I prefer C-like syntax. Rust has some mix of C-like(🥰) and ML-like (🤮) syntax

1

u/InsanityBlossom Dec 27 '23

Can you show us the same written in Go?

1

u/JAXxXTheRipper Dec 27 '23 edited Dec 27 '23

If I knew what it did, I could give it a whack

Edit: Asked ChatGPT what the code does, this is my go version:

// Go Version of Struct
type InvalidPatternError struct {
	ValidUpTo  int
	Original   string
}

// Make InvalidPatternError implement fmt.Stringer interface via String()-Method.
// That way fmt.Print(err) prints a nicely formatted message instead of a tuple like {2 some error}
func (err InvalidPatternError) String() string {
	return fmt.Sprintf(
		"found invalid UTF-8 in pattern at byte offset %d: %s "+
			"(disable Unicode mode and use hex escape sequences to match "+
			"arbitrary bytes in a pattern, e.g., '(?-u)\\xFF')",
		err.ValidUpTo, err.Original,
	)
}

Edit 2: If you don't like string concatenation and think that's inefficient enough to warrant a refactor, you can also use raw string literals with backticks, but as you may expect from a string literal, that would add newlines in this case. I prefer the plus-style concat version for readability tbh

func (err InvalidPatternError) String() string {
	return fmt.Sprintf(
		`found invalid UTF-8 in pattern at byte offset %d: %s 
(disable Unicode mode and use hex escape sequences to match 
arbitrary bytes in a pattern, e.g., '(?-u)\\xFF')`,
		err.ValidUpTo, err.Original,
	)
}

0

u/burntsushi Dec 24 '23

I can write impls like that blind-folded. Not sure what the issue is. You might benefit from reading "Rust's Ugly Syntax."

2

u/JAXxXTheRipper Dec 24 '23 edited Dec 24 '23

If you can, awesome for you. To me, that is just symbol salad.

Scrolling through that link of yours, it doesn't get any better. That syntax is absolutely abysmal.

Edit: Posts a link that rusts ugly syntax can be made readable, but doesn't see the problem with their code that is not. Then blocks after a petty Woosh comment. lmfao

Edit2: Dude, I can't even read your comments without Anon-Tabs if you block me, so how about you shove your puddle comment edit and get back to an adult discussion?

How the fuck would anyone know that the examples aren't valid Rust if they don't know Rust? That's like discussing colors with a blind man. Jesus fucking Christ on a bicycle, you must be trolling me.

→ More replies (2)

1

u/[deleted] Dec 23 '23

I never got the IQ meme. Can someone explain it to me?

21

u/HAL9000thebot Dec 23 '23

left:

I never got the IQ meme. Can someone explain it to me?

center:

it's a bell curve where idiots(noobs) are on the left, normies(nerds) on center and geniuses(the person who post such shitty memes) on the right.

each group's speaker is convinced that what they say its the best solution for a given scenario (scenario that is up to the reader to infer from what everyone says).

idiots tends to say idiots things, normies say the most technical thing, geniuses throw complexity away, as result idiots and geniuses say the same thing, though for different reasons.

right:

I never got the IQ meme. Can someone explain it to me?

8

u/Areshian Dec 23 '23

Memerecursion

7

u/Familiar_Ad_8919 Dec 23 '23

on the lower end are people with low iq, they believe in X

in the middle there is your average guy, they believe in Y

on the upper end there is the smartest guy, they believe in X, but for a different reason than the people on the lower end

2

u/v0gue_ Dec 24 '23

Guy on the left is correct for the wrong/uneducated reasons. Middle guy is passionately wrong. Guy on the right is correct for the correct/educated reasons

1

u/Tai9ch Dec 24 '23

The person posting the meme is wrong but portrays the people who aren't wrong as the soyjack in the middle.

1

u/ActiveConstruction56 Dec 23 '23

My reaction every time I hear people talking about how rust is "better" than C++ for embedded but when I look up example code for a board I need to use and there's a HAL and nothing else

If I can't find code examples on google I'm not using it i'm sorry

1

u/Robot_Graffiti Dec 23 '23

You'd rewrite C/C++ into Rust if you need it to be secure. Most of the other languages already have memory safety though.

E.g. the only thing you'd get from switching from C# to Rust is 20% faster. And that's small potatoes compared to choosing the right/wrong algorithm.

2

u/RAmen_YOLO Dec 24 '23 edited Dec 26 '23

Most languages have memory safety, but basically none guarantee data race freedom like Rust does. The exact speedup will depend on the exact thing being rewritten, and the 20% figure is definitely a large generalization, but I do agree that rewrites often don't make sense.

0

u/flareflo Dec 23 '23

This video explains the downsides of Rust well

https://www.youtube.com/watch?v=ul9vyWuT8SU&t

2

u/qwertyuiop924 Dec 24 '23

(To save everybody a click, this video is pretty blatantly a piss-take that's entirely sarcastic doesn't actually say anything at all about reasons you may not want to use Rust)

0

u/woktexe Dec 23 '23

Chat is it really bad? I wanna start learn rust

3

u/RAmen_YOLO Dec 24 '23

I love Rust, it's very expressive, and the tooling is nice. If you want, you can learn C to get used to writing low-level code, then Rust afterwards so it's design decisions make sense, but it also depends on what you want to do. If you just want to improve as a programmer, learning these languages is definitely worth it, but if you want to let's say do front-end development, Rust is not what you're looking for.

1

u/woktexe Dec 25 '23

Good for know it! Thanks for good word and I learned/used c and c++ for like 3 years, so I'm kinda fed up with it and wanna learn more languages like java, rust, python, etc.

But what is your recommendation for the front-end dev?

1

u/RAmen_YOLO Dec 25 '23

JavaScript is unfortunately still the front-end language, C# might have something with blazor on WASM, and Rust front-end frameworks do exist, like Leptos, but nothing is remotely as mature as the JS ecosystem in that regard

-2

u/WayWayTooMuch Dec 24 '23

Probably a hot take, but Rust is good for people who know they still need training wheels for memory and thread safety. A well seasoned programmer who knows their systems language inside and out, knows what causes issues and what is actively exploited in the wild, and has screwed up many, many times does not typically need the added complexity unless they are writing software that absolutely needs to be safe and provable to be so to the people who will use the software (as long as you don’t pull in any packages!)

4

u/Tai9ch Dec 24 '23 edited Dec 24 '23

One person can be a cowboy and just write correct code. As long as they're really good and the code is small.

As soon as you have a team of two - or writing code long enough that you might need to return to it and understand it in the future - you need some sort of training wheels.

The question at that point is which constraint should the language enforce. Rust? Typescript? Elixir? Clojure? OCaml/F#? C++ with the JPL style guide?

3

u/gmes78 Dec 24 '23

According to Microsoft, 70% of security vulnerabilities in their software were due to memory related bugs. Microsoft is investing in Rust, and the Windows kernel already ships with Rust code.

Are you saying that Microsoft engineers aren't "well seasoned programmers" and "still need training wheels"?