News for hackers. Stuff that matters.
Re:The computers are fast, but you don't know it by munificent on Thursday June 16, 2022 @03:53PM (#31770183)
I agree 100%. I wish every software engineer would spent at least a little time writing some programs in bare C and running them to get a feel for how fast a native executable can start up and run. It is breathtaking if you're used to running scripting languages and VMs.

Related anecdote: My blog used to be written using Jekyll with Pygments for syntax highlighting. As the number of posts increased, it got closer and closer. Eventually, it took about 20 seconds to refresh a simple text change in a single blog post.

I eventually decided to just write my own damn blog engine completely from scratch in Dart. Wrote my own template language, build graph, and syntax highlighter. By having a smart build system that knew which pages actually needed to be regenerated based on what data actually changed, I hoped to get very fast incremental rebuilds in the common case where only text inside a single post had changed.

Before I got the incremental rebuild system working, I worked on getting it to just to a full build of the entire blog: every post page, pages, for each tag, date archives, and RSS support. I diffed it against the old blog to ensure it produced the same output.

Once I got that working... I realized I didn't even need to implement incremental rebuilds. It could build the entire blog and every single post from scratch in less than a second.

I don't know how people tolerate slow frameworks and build systems.

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:39PM (#31770713)
Yeah, I've written static site generators in Go and Rust among other languages (it's my goto project for learning a new language). Neither needed incremental builds because they build instantly. The bottlenecks are I/O.

I've also worked in Python shops for the entirety of my career. There are a lot of Python programmers who don't have experience with and thus can't quite believe how much faster many other languages are (100X-1000X sounds fast in the abstract, but it's really, really fast). I've seen engineering months spent trying to get a CPU-bound endpoint to finish reliably in under 60s (yes, we tried all of the "rewrite the hot path in X" things), while a naive Go implementation completed in hundreds of milliseconds.

Starting a project in Python is a great way to paint yourself into a corner (unless you have 100% certainty that Python [and "rewrite hot path in X"] can handle every performance requirement your project will ever have). Yeah, 3.11 is going to get a bit faster, but other languages are 100-1000X faster--too little, too late.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @05:51AM (#31776048)
Python is slow in many things like pure looping and arithmetic, even though there are workarounds to make that 1-10x slower rather than 100-1000X (eg. C-based implementations, including all the itertools stuff).

I am sometimes frustrated that I can't just loop over a string character by character and not get crappy performance, but the "problem" you (and me) are seeing in existing codebases is that Python is very inviting to beginners, and they are not frustrated with this because they don't know it :)

But as you note, bottleneck is the I/O, and a program waiting for I/O in Python and I/O in C will wait the same time after the computation is done.

If you are writing software that can parallelize well independently (eg. web apps) and your memory pressure is not the most important thing, you simply run multiple Python processes to max out the CPU (this avoids the GIL unlike async Python). And you keep your dependencies low.

Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @09:17AM (#31777671)
> even though there are workarounds to make that 1-10x slower rather than 100-1000X (eg. C-based implementations, including all the itertools stuff).

These only apply for specific problems, and very few applications are purely CSV parsing or purely matrix math operations. In the real world, you often spend more time marshaling your Python data to C than you save by doing your computation in C.

> But as you note, bottleneck is the I/O, and a program waiting for I/O in Python and I/O in C will wait the same time after the computation is done.

The bottleneck in a static site generator is I/O. The fact that Python, Ruby, etc based implementations take tens of seconds or more while Go and Rust finish instantly for an I/O bound problem is pretty damning.

> If you are writing software that can parallelize well independently (eg. web apps) and your memory pressure is not the most important thing, you simply run multiple Python processes to max out the CPU (this avoids the GIL unlike async Python).

The goal isn’t to saturate the CPU as much as it is to complete requests in a timely fashion. If it’s just some light translation between HTTP and database layers, Python is fine, but if you have to do anything computationally significant at all, it can range from “a huge pain” to “virtually impossible”. I gave the example earlier of a web service that was struggling to complete requests in even 60s (despite using Numpy under the hood where possible) while a naive Go implementation completed in hundreds of ms.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @11:11AM (#31779356)
> The bottleneck in a static site generator is I/O. The fact that Python, Ruby, etc based implementations take tens of seconds or more while Go and Rust finish instantly for an I/O bound problem is pretty damning.

My point was that if this was the case, your Python code is probably suboptimal.

Sure, you are comparing against naive implementation as well, but if performance is a concern, don't do naive Python :)

> I gave the example earlier of a web service that was struggling to complete requests in even 60s (despite using Numpy under the hood where possible) while a naive Go implementation completed in hundreds of ms.

Yes, it's easy and sometimes even idiomatic to write non-performant Python code. Getting the most out of pure Python is hard and it means avoiding some common patterns.

Eg. simply using sqlalchemy ORM (to construct rich dynamic ORM objects) instead of sqlalchemy core (tuples) to get 100k+ rows from DB is 20x slower, and that's still 2x slower from pure psycopg (also tuples using basic types). There are plenty of examples like this in Python, unfortunately.

Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @03:21PM (#31783033)
> My point was that if this was the case, your Python code is probably suboptimal. Sure, you are comparing against naive implementation as well, but if performance is a concern, don't do naive Python :)

I agree, and I'll go further: if performance could be a concern and you aren't certain that even optimized Python is up for the task, don't do Python. :)

I don't know how optimized these SSGs are, but given how frequently this complaint occurs and how popular they are, I would expect that someone would have tried to optimize them a bit. Even assuming naive implementations, tens of seconds versus tens of milliseconds for an I/O-bound task is pretty concerning.

> Yes, it's easy and sometimes even idiomatic to write non-performant Python code. Getting the most out of pure Python is hard and it means avoiding some common patterns.

It probably shouldn't be easy for someone to write non-performant Python code when they're trying desperately to write performant Python code. :)

> Getting the most out of pure Python is hard and it means avoiding some common patterns.

And even then, you're probably going to be coming in 10-100X slower than naive Go/Java/C#/etc unless your application happens to be a good candidate for C-extensions (e.g., matrix math) or if it really is I/O bound (a CRUD webapp). It honestly just seems better to avoid Python altogether than try to write Python without using "common patterns" (especially absent guidance about which patterns to avoid or how to avoid them).

Re:The computers are fast, but you don't know it by jcelerier on Thursday June 16, 2022 @03:57PM (#31770238)
> I agree 100%. I wish every software engineer would spent at least a little time writing some programs in bare C and running them to get a feel for how fast a native executable can start up and run. It is breathtaking if you're used to running scripting languages and VMs.

Conversely when 99.9% of the software you use in your daily life is blazing fast C / C++, having to do anything in other stacks is a complete exercise in frustration, it feels like going back a few decades in time

Re:The computers are fast, but you don't know it by p1esk on Thursday June 16, 2022 @04:00PM (#31770269)
Conversely when 99.9% of the software you use in your daily life is user friendly Python, having to do anything in C/C++ is a complete exercise in frustration, it feels like going back a few decades in time
Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @04:17PM (#31770456)
As a person who uses both languages for various needs, I disagree. Things which takes minutes in optimized C++ will probably take days in Python, even if I use the "accelerated" libraries for matrix operations and other math I implement in C++.

Lastly, people think C++ is not user friendly. No, it certainly is. It needs being careful, yes, but a lot of things can be done in less lines then people expect.

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:43PM (#31770748)
I was a C++ dev in a past life and I have no particular fondness for Python (having used it for a couple of decades), and "friendliness" is a lot more than code golf. It's also "being able to understand all of the features you encounter and their interactions" as well as "sane, standard build tooling" and "good debugability" and many other things that C++ lacks (unless something has changed recently).
Re:The computers are fast, but you don't know it by jb_s on Friday June 17, 2022 @01:12AM (#31774350)
I delved into Python recently to work on some data science hobbies and a Chess program and it's frankly been fairly shit compared with other languages I use.

Typescript (by way of comparison with other non-low-level languages) just feels far more solid wrt type system, type safety, tooling etc. C# (which I've used for years) is faster by orders of magnitude and IMO safer/easier to maintain.

Re:The computers are fast, but you don't know it by rocqua on Friday June 17, 2022 @04:28AM (#31775532)
I have found that Python with `mypy --strict` for type-checking is actually quite nicely typed.
Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @05:57AM (#31776073)
Python is a powerful yet beginner friendly language with a very gentle learning slope, but I would still take C++ tooling and debuggability any day over Python.
Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @10:18AM (#31778570)
Nah man, I've spent way too much time trying to piece together libraries to turn core dumps into a useful stack trace. Similarly, as miserable as Python package management is, at least it has a package manager that works with virtually every project in the ecosystem. I actually really like writing C++, but there are certain obstacles that slow a developer down tremendously--I could forgive them if they were interesting obstacles (e.g., I can at least amuse myself pacifying Rust's borrow checker), but there's no joy in trying to cobble together a build system with CMake/etc or try to get debug information for a segfault.
Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @10:39AM (#31778893)
I won't spend any positive words on cmake (I'm a plain make fan), but...

> or try to get debug information for a segfault

what's the problem with opening the core dump with gdb and looking at the backtrace?

Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @02:41PM (#31782516)
You need to provide all of the libraries referenced by the core dump (at the specific versions and compiled with debug symbols) to get gdb to produce a useful backtrace. It's been a decade since I've done professional C++ development, so I'm a bit foggy on the particulars.
Re:The computers are fast, but you don't know it by jcelerier on Friday June 17, 2022 @04:06PM (#31783558)
we're in 2022, gdb asks me "can i download missing symbols from the internet" when it loads a binary and does it
Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @09:26PM (#31786516)
Glad to hear the 2022 C++ ecosystem is finally catching up on some regards, but how does it know which version of those dependencies to download, and how does it download closed source symbols?
Re:The computers are fast, but you don't know it by jcelerier on Saturday June 18, 2022 @03:35AM (#31787950)
I mean, if it's closed source you're not getting the debug symbols in any case lol, no matter which language.

It uses debuginfod for fetching symbols - here it "just works".

Re:The computers are fast, but you don't know it by TremendousJudge on Friday June 17, 2022 @06:35AM (#31776277)
>unless something has changed recently

No, it's even worse -- there are even MORE ways of doing the same thing now.

Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @04:36PM (#31770681)
Java and Go were both responses to how terrible C++ actually is. While there are footguns in python, java, and go, there are exponentially more in C++.
Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @04:41PM (#31770730)
As a person who wrote Java and loved it (and I still love it), I understand where you're coming from, however all programming languages thrive in certain circumstances.

I'm no hater of any programming language, but a strong proponent of using the right one for the job at hand. I write a lot of Python these days, because I neither need the speed, nor have the time to write a small utility which will help a user with C++. Similarly, I'd rather use Java if I'm going to talk with bigger DBs, do CRUD, or develop bigger software which is going to be used in an enterprise or similar setting.

However, if I'm writing high performance software, I'll reach for C++ for the sheer speed and flexibility, despite all the possible foot guns and other not-so-enjoyable parts, because I can verify the absence of most foot-guns, and more importantly, it gets the job done the way it should be done.

Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @04:55PM (#31770862)
I've seen a lot of bad C++ in my life, and have seen Java people write C++ like they would Java.

Writing good C++ is hard. People who think they can write good C++ are surprised to learn about certain footguns (static initialization before main, exception handling during destructors, etc).

I found this reference which I thought was a pretty good take on the C++ learning curve.

https://www.reddit.com/r/ProgrammerHumor/comments/7iokz5/c_l...

Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @05:02PM (#31770943)
> I've seen a lot of bad C++ in my life, and have seen Java people write C++ like they would Java.

Ah, don't remind me Java people write C++ like they write Java, I've seen my fair share, thank you.

> Writing good C++ is hard.

I concur, however writing good Java is also hard. e.g. Swing has a fixed and correct initialization/build sequence, and Java self-corrects if you diverge, but you get a noticeable performance hit. Most developers miss the signs and don't fix these innocent looking mistakes.

I've learnt C++ first and Java later. I also tend to hit myself pretty hard during testing (incl. Valgrind memory sanity and Cachegrind hotpath checks), so I don't claim I write impeccable C++. Instead I assume I'm worse than average and try to find what's wrong vigorously and fix them ruthlessly.

Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @04:55AM (#31775697)
> Ah, don't remind me Java people write C++ like they write Java, I've seen my fair share, thank you.

I always find this remark amusing, given that Java adopted the common patterns in C++ toolkits that precedded Java.

If anything they are writting C++ like it used to be on Turbo Vision, Object Windows Library, MPW, PowerPlant, MFC, wxWindows,....

Re:The computers are fast, but you don't know it by bayindirh on Friday June 17, 2022 @05:18AM (#31775840)
The remark is rooted from variable naming and code organization mostly. I've seen a C++ codebase transferred to a java developer, and he disregarded everything from the old codebase. Didn't refactor the old code, and the new additions were done Java Style. CamelCase file/variable/function names, every class on its own file with ClassName.cpp files littered everywhere, it was a mess.

The code was math-heavy, and became completely unreadable and un-followable. He remarked "I'm a java developer, I do what I do, and as long as it works, I don't care".

That was really bad. It was a serious piece of code, in production.

Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @06:20AM (#31776196)
So basically " like it used to be on Turbo Vision, Object Windows Library, MPW, PowerPlant, MFC, wxWindows,..."
Re:The computers are fast, but you don't know it by rot13xor on Thursday June 16, 2022 @06:28PM (#31771777)
The biggest weakness of C++ (and C) is non-localized behavior of bugs due to undefined behavior. Once you have undefined behavior, you can no longer reason about your program in a logically consistent way. A language like Python or Java has no undefined behavior so for example if you have an integer overflow, you can debug knowing that only data touched by that integer overflow is affected by the bug whereas in C++ your entire program is now potentially meaningless.
Re:The computers are fast, but you don't know it by kllrnohj on Thursday June 16, 2022 @07:31PM (#31772269)
That is a radically gross misunderstanding of what undefined behavior is and how it can (and mostly how it cannot) propagate.
Re:The computers are fast, but you don't know it by Too on Saturday June 18, 2022 @01:19AM (#31787420)
Memory write errors (some times induced by UB) in one place of the program can easily propagate and later fail in a very different location of the program, with absolutely zero diagnostics of why your variable suddenly had a value out of possible range.

This is why valgrind, asan and friends exist. They move the error diagnostic to the place where error actually happened.

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @04:31AM (#31775546)
Actually it's not, Chandler Carruth notwithstanding.

If your C++ program exhibit undefined behaviour, the compiler is allowed to format your entire hard drive. Or encrypt it and display a "plz pay BTC" message. That's called a vulnerability. Real and meaningful security checks have been removed as "dead code" because of signed integer overflow (which is undefined behaviour by default).

If anything, I would guess the gross misunderstanding sprouted somewhere between the specs and the compiler writers. Originally, UB was mostly about bailing out when the underlying platform couldn't handle this particular case, or explicitly ignoring edge cases to simplify implementations. Now however it's also a performance thing, and if anything is marked as UB then it's fair game for the optimiser — even if it could easily be well defined, like signed integer overflow on 2's complement platforms.

Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @06:28AM (#31776241)
> If your C++ program exhibit undefined behaviour, the compiler is allowed to format your entire hard drive. Or encrypt it and display a "plz pay BTC" message.

No, it isn't. That's a completely made up fabrication. And if you had a compiler that was going to do that, then what the standard says or if there's undefined behavior is obviously not relevant or significant in the slightest.

The majority of the UB optimization complaints are because the compiler couldn't tell that UB was happening. It didn't detect UB and then make an evil laugh and go insane. That's not how this works.

Compilers cannot detect UB and then do things in response within the rules of the standard. Rather, they are allowed to assume UB doesn't happen. That's it, that's all they do. They just behave as though your source has no UB at all. As far as the compiler is concerned, UB doesn't exist and can't happen.

When a compiler can detect that UB is happening it'll issue a warning. It never silently exploits it.

> Real and meaningful security checks have been removed as "dead code" because of signed integer overflow (which is undefined behaviour by default).

Real and meaningful security checks have been removed because the security check happened after the values were already used in specific ways, not because of UB. The values were already specified in the source code to be a particular thing via earlier usage. UB is just the shield for developers who wrote a bug to hide behind to avoid admitting they had a bug.

Use UBSAN next time.

> even if it could easily be well defined, like signed integer overflow on 2's complement platforms.

Signed integer overflow is defined behavior, that's not UB. Also platform specific behavior is something the standard doesn't define - that's why it was UB in the first place.

It is kinda ridiculous it took until C++20 for this change, though

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @09:55AM (#31778201)
> > UB allows the to format/encrypt your entire hard drive.

> No, it isn't. That's a completely made up fabrication.

Ever heard of viruses exploiting buffer overflows to make arbitrary code execution? One cause of that can be a clever optimisation that noticed that the only way the check fails is when some UB is happening. Since UB "never happens", the check is dead code and can be removed. And if the compiler noticed after it got past error reporting, you may not even get a warning.

You still get the vulnerability, though.

> UB is just the shield for developers who wrote a bug to hide behind to avoid admitting they had a bug.

C is what it is, and we live with it. Still, it would be unreasonable to say that the amount of UB it harbours isn't absolutely ludicrous. It's like asking children to cross a poorly mapped minefield and blame them when they don't notice a subtle cue and blow themselves up.

Also, UBSan is not enough. I ran some of my code unde ASan, MSan, and UBSan, and the TIS interpreter still found a couple things. And I'm talking about pathologically straight-line code where once you test for all input sizes you have 100% code path coverage.

> Signed integer overflow is defined behavior, that's not UB.

The C99 standard explicitly states that left shift is undefined on negative integers, as well as signed integers when the result overflows. I had to get around that one personally by replacing x<<n by x(1<<n) on carry propagation code.

Strangely enough I cannot find explicit mentions of signed integer overflow for regular arithmetic operators, but apparently the C++ standard has an explicit mention: https://stackoverflow.com/questions/16188263/is-signed-integ...

> Also platform specific behavior is something the standard doesn't define - that's why it was UB in the first place.*

One point I was making is, compiler writers didn't get that memo. They treat any UB as fair game for their optimisers. It doesn't matter that signed integer overflow was UB because of portability, it still "never happens".

Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @10:28AM (#31778734)
> C is what it is, and we live with it. Still, it would be unreasonable to say that the amount of UB it harbours isn't absolutely ludicrous.

There's a lot of ludicrous stuff about C and I wouldn't recommend anyone use it for anything. Not when Rust and C++ exist.

But UB really isn't the scary boogie man. There could probably stand to be a `as-is {}` block extension for security checks, but that's really about it.

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @10:46AM (#31778978)
I'm sorry, C++?!?

Granted, C is underpowered and I would like namespaces and generics. But from a safety standpoint nowadays, C++ is just as bad. Not only is is monstrously complex, it still has all the pitfalls of C. C++ may have been "more strongly typed" back in the day, but now compiler warnings made up for that small difference.

Granted, C++ can be noticeably safer if you go RAII pointer fest, but then you're essentially programming in Java with better code generation and a worse garbage collector.

---

There's also a reason to still write C today: its ubiquity. Makes it easier to deploy everywhere and to talk to other languages. It's mostly a library thing though, and the price in testing effort and bugs is steep.

Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @07:00PM (#31785548)
> I'm sorry, C++?!?

C++ had a defined multithreaded memory model and 2's compliment behavior before C did. Since you're all about UB, that kinda matters. A lot.

Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @08:06PM (#31786072)
Well, I'll check who gets rid of all undefined overflows first. 2's complement is nice and dandy, but if overflow is still undefined that doesn't buy me much.

Point taken about multi threading.

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:45PM (#31770767)
I've written a whole bunch of all of those languages, and they each occupy a different order of magnitude of footguns. From fewest to most: Go (1X), Java (10X), Python (100X), and C++ (1000X).
Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:49PM (#31771976)
Go has much more footguns in my opinion. Just look at the recent thread on the topic: https://news.ycombinator.com/item?id=31734110
Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @10:04PM (#31773324)
Most of those aren’t “footguns” at all, but rather preferences (naming conventions, nominal vs structural subtyping) and many others are shared with Python (“magical behavior”, Go’s structural subtyping is strictly better for finding implementations than Python’s duck typing) or non-issues altogether (“the Go compiler won’t accept my invalid Go code”).

The “forget to check an error” one is valid, but rare (usually a function will return data and an error, and you can’t touch the data without handling the error)—moreover, once you use Go for a bit, you sort of expect errors by default (most things error). But yeah, a compilation failure would be better. Personally, the things that really chafe me are remembering to initialize maps, which is a rarer problem in Python because there’s no distinction between allocation and instantiating (at least not in practice). I do wish Go would ditch zero types and adopt sum types (use Option[T] where you need a nil-like type), but that ship has sailed.

I’ve operated services in both languages, and Python services would have tons of errors that Go wouldn’t have, including typos in identifiers, missing “await”s, “NoneType has no attribute ‘foo’”, etc but also considerably more serious issues like an async function accidentally making a sync call under the covers, blocking the event loop, causing health checks to fail, and ultimately bringing down the entire service (same deal with CPU intensive endpoints).

In Go, we would see the occasional nil pointer error, but again, Python has those too.

Re:The computers are fast, but you don't know it by astrange on Thursday June 16, 2022 @11:42PM (#31773882)
Java is largely based on Objective-C, not on C++. It's a bit hard to tell because they removed messaging though.

It is memory safe but otherwise I think it was an imitation, not a reaction, to ObjC features.

Re:The computers are fast, but you don't know it by LoveMortuus on Thursday June 16, 2022 @04:52PM (#31770833)
I personally find C++ more friendly, just because of the formatting that python forces upon you.

But I do have to say that I never managed to really get into python, it always just felt like to much of a hassle, thus I always avoided it if possible.

Re:The computers are fast, but you don't know it by chowells on Friday June 17, 2022 @02:18AM (#31774667)
The formatting python enforces is just "layout reflects control flow". It's really not any more difficult than that, and it's a lot better than allowing layout to lie about control flow.

https://www.synopsys.com/blogs/software-security/understandi...

Re:The computers are fast, but you don't know it by doctor_eval on Friday June 17, 2022 @08:31AM (#31777123)
To each their own, but Python's use of indenting for structure is why I never tried it. It just felt, to me, like it was solving one problem with another.

I think Go gets this right: it consistently uses braces for structure, but has an idiomatic reformatting tool that is applied automatically by most IDEs. This ensures that the format and indentation always perfectly matches the code structure, without needing to use invisible characters.

Re:The computers are fast, but you don't know it by idlehand on Thursday June 16, 2022 @05:12PM (#31771029)
I didn't like it for years but then I kind of got into it for testing out machine learning and I found it kind of neat. My biggest gripe is no longer the syntax but the slowness, trying to do anything with even a soft performance requirement means having to figure out how to use a library that calls C to do it for you. Working with large amounts of data in native Python is noticeably slower than even NodeJS.
Re:The computers are fast, but you don't know it by l33t2328 on Friday June 17, 2022 @02:49AM (#31774872)
> Things which takes minutes in optimized C++ will probably take days in Python, even if I use the "accelerated" libraries for matrix operations and other math

I’m gonna need an example because I do not believe this whatsoever.

Re:The computers are fast, but you don't know it by bayindirh on Friday June 17, 2022 @02:56AM (#31774925)
I'd rather open the code and show what I'm talking about, however I can not.

Let's say I'm making a lot of numerical calculations which are fed from a lockless queue with atomic operations to any number of cores you want, where your performance is limited by the CPU cores' FPU performance and the memory bandwidth (in terms of both transfer speed and queries that bus can handle per second).

As I noted below, that code can complete 1.7 million complete evaluations per core, per second on older (2014 level) hardware, until your memory controller congests with all the requests. I need to run benchmarks on a newer set of hardware to get new numbers, however I seriously lack the time today to do so and provide you new numbers.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @06:45AM (#31776346)
There are definitely operations you cannot speed up in Python as much as in other languages, unless you implement it in one of those other languages and interface it in Python.

That much is obvious from Python providing a bunch of C-based primitives in stdlib (otherwise they'd just be written in pure Python).

In many cases, you can make use of the existing primitives to get huge improvements even with pure Python, but you are not beating optimized C++ code (which almost has direct access to CPU vector operations as well).

Python's advantage is in speed of development, not in speed of execution. And I say that as a firm believer that majority of the Python code in existence today could be much faster only if written with the understanding of Python's internal structures.

Re:The computers are fast, but you don't know it by p1esk on Thursday June 16, 2022 @04:27PM (#31770580)
Which “accelerated” libraries for matrix operations are you talking about?

Try writing a matmul operation in C++ and profile it against the same thing done in Numpy/Pytorch/TensorFlow/Jax. You’ll be surprised.

Re:The computers are fast, but you don't know it by gpm on Thursday June 16, 2022 @04:39PM (#31770701)
This is because numpy and friends are really good at matmul's.

As soon as you step out of the happy path and need to do any calculation that isn't at least n^2 work for every single python call you are looking at order of magnitude speed differences.

Years ago now (so I'm a bit fuzzy on the details) a friend asked me to help optimize some python code that took a few days to do one job. I got something like a 10x speedup using numpy, I got a further 100x speedup (on the entire program) by porting one small function from optimized numpy to completely naive rust (I'm sure c or c++ would have been similar). The bottleneck was something like generating a bunch of random numbers, where the distribution for each one depended on the previous numbers - which you just couldn't represent nicely in numpy.

What took 2 days now took 2 minutes, eyeballing the profiles I remember thinking you could almost certainly get down to 20 seconds by porting the rest to rust.

Re:The computers are fast, but you don't know it by rubyskills on Thursday June 16, 2022 @05:41PM (#31771336)
Have you tried porting the problem into postgres? Not all big data problems can be solved this way but I was surprised what a postgres database could do with 40 million rows of data.
Re:The computers are fast, but you don't know it by gpm on Thursday June 16, 2022 @06:03PM (#31771571)
I didn't, I don't think using a db really makes sense for this problem. The program was simulating a physical process to get two streams of timestamps from simulated single-photon detectors, and then running a somewhat-expensive analysis on the data (primarily a cross correlation).

There's nothing here for a DB to really help with, the data access patterns are both trivial and optimal. IIRC it was also more like a billion rows so I'd have some scaling questions (a big enough instance could certainly handle it, but the hardware actually being used was a cheap laptop).

Even if there was though - I would have been very hesitant to do so. The not-a-fulltime-programmer PhD student whose project this was really needed to be able to understand and modify the code. I was pretty hesitant to even introduce a second programming language.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @06:35AM (#31776278)
That's definitely quite curious: I am sure pure Python could have been heavily optimized to reach 2 minutes as well, though. Random number generation in Python is C-based, so while the pseudo-random generators from Python's random module might be slow, it's not because of Python itself (https://docs.python.org/3/library/random.html is a different implementation from https://man7.org/linux/man-pages/man3/random.3.html).

Call overhead and loop overhead is pretty big in Python though. The way to work around that in Python is to use C-based "primitives", like the stuff from itertools and all the builtins for set/list/hash processing (thus avoiding the n^2 case in pure Python). And when memory is an issue (preallocating large data structures can be slow as well), iterators! (Eg. compare use of range() in newer Python with use of list(range())).

Re:The computers are fast, but you don't know it by gpm on Friday June 17, 2022 @02:33PM (#31782416)
I'm reasonably sure the PRNG being used in the python version came from numpy and was implemented in C (or other native code, not python). The problem was that the necessary control flow and varying parameters around it meant you had to call it once per value from python (and you had to generate a lot of values).

And if I recall correctly there was no allocation in the hot loop, with a single large array being initialized via numpy to store the values before hand. Certainly that's one of the first things I would think to fix.

I was strongly convinced at the time that there was no significant improvement left in python. With >99% of the time being spent in this one function, and no way to move the loop into native code given the primitives available from numpy. Admittedly I could have been wrong, and I'm not about to revisit the code now, since it has been years and it is no longer in use - so everything I'm saying is based off of years old memories.

Re:The computers are fast, but you don't know it by necovek on Saturday June 18, 2022 @09:10AM (#31789515)
Sure, numpy introduces its own set of restrictions. I was mostly referring to taking a different approach before turning to numpy, but it could very well be true.

In essence, doing what you did is the way to get performance out of Python when nothing else works.

Re:The computers are fast, but you don't know it by dragonwriter on Friday June 17, 2022 @02:45PM (#31782571)
> The problem was that the necessary control flow and varying parameters around it meant you had to call it once per value from python (and you had to generate a lot of values).

Sounds like a Numba use case.

Re:The computers are fast, but you don't know it by gpm on Friday June 17, 2022 @02:51PM (#31782654)
Huh, I didn't know that was a thing. At a super high level glance I suspect yes.
Re:The computers are fast, but you don't know it by bayindirh on Thursday June 16, 2022 @04:35PM (#31770676)
The code I've written and still working on is using Eigen, which TensorFlow also uses for its matrix operations, so, I'm not far off from these guys in terms of speed, if not ahead.

The code I've written can complete 1.7 million evaluations per core, per second, on older hardware, which is used to evaluate things up to 1e-6 accuracy, which pretty neat for what I'm working on.

[0]: https://eigen.tuxfamily.org/index.php?title=Main_Page

Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @01:17AM (#31774364)
Doesn't numpy use a natively compiled Fortran or c library for that?

https://github.com/numpy/numpy/blob/main/numpy/core/src/mult...

Re:The computers are fast, but you don't know it by p1esk on Friday June 17, 2022 @02:22AM (#31774702)
Why should I care what Numpy is written in? All I see is Python.
Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @03:26AM (#31775133)
Because it is like saying you use a bash script to configure and launch a c++ application and saying it is a bash script. Python is not a high performance language, it isn't meant to be and it's strengths lie elsewhere. One of it's great strengths is interop with c libs.

Your assertion was that numpy etc will be faster than something else despite being python:

> Try writing a matmul operation in C++ and profile it against the same thing done in Numpy/Pytorch/TensorFlow/Jax. You’ll be surprised.

I mean TensorFlow is c++/cuda!

Re:The computers are fast, but you don't know it by p1esk on Friday June 17, 2022 @04:12AM (#31775433)
I mean TensorFlow is c++/cuda!

No. When I write Tensorflow code I write Python. I don’t care what TF does under the hood just like I don’t care that Python itself might be implemented in C. Though I got to say TF is quite ugly and not a good example of Python’s user friendliness. But that’s another topic.

Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @06:00AM (#31776093)
But as soon as you step out of the optimized path, the performance cliff is huge. Also you are forced to work in non idiomatic awkward meta-languages.
Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @05:35AM (#31775958)
As long as you know python is doing little to no computational work.
Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @06:40AM (#31776314)
That's a known and widely publicised trait of Python.

In the early days, Python tutorial warned against adding to strings by doing "+" even though it works because that performed a new allocation and string copy.

What you were asked to do was use fast, optimized C-based primitives like "\n".join(list_of_strings) etc.

Basically, Python is an "ergonomic" language built in C. Saying how something is implemented in C at the lower level is pointless, because all of Python is.

Yes, doing loops over large data sets in Python is slow. Which is why it provides itertools (again, C-based functions) in stdlib.

Re:The computers are fast, but you don't know it by gilbetron on Thursday June 16, 2022 @08:48PM (#31772797)
Aren't the fast parts of numpy written in C?
Re:The computers are fast, but you don't know it by gpm on Thursday June 16, 2022 @09:06PM (#31772918)
And fortran. Which really doesn't matter that much as long as that doesn't leak to the users of numpy, and it doesn't really. The only issue is that it means if you're doing something that doesn't fit the APIs exposed by the native code (in a way where the hot loops are in native code) it's roughly as slow as normal python.
Re:The computers are fast, but you don't know it by gilbetron on Friday June 17, 2022 @08:18AM (#31777010)
But it does for the argument of a language being fast, which is what we are talking about here. I don't think it is an appropriate argument to say "Python is fast, look at numpy", when the core pieces are written in C/Fortran. It is disingenuous, at least to me.
Re:The computers are fast, but you don't know it by Shorel on Friday June 17, 2022 @02:43PM (#31782538)
The canonical answer would be uBLAS.

https://www.boost.org/doc/libs/1_75_0/libs/numeric/ublas/doc...

I think BLAS (a C version, not the boost one) is also the library numpy is using, as numpy is not written in python. That's why it is fast, it is C.

Re:The computers are fast, but you don't know it by tcfhgj on Friday June 17, 2022 @01:17PM (#31781296)
C++ isn't remotely user friendly.

Have you ever tried Rust? Compared to C++, it's like heaven

Re:The computers are fast, but you don't know it by tcfhgj on Thursday June 16, 2022 @07:18PM (#31772191)
C++ isn't user friendly.

Have you ever tried Rust? Compared to C++, it's like lawyer speech vs poetry

Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:45PM (#31771932)
I call bullshit on that. You either don’t compare the same thing, but C++ is not that much faster than even Python.
Re:The computers are fast, but you don't know it by easytiger on Friday June 17, 2022 @01:19AM (#31774373)
That's simply not even remotely true, as someone who has written a lot of both
Re:The computers are fast, but you don't know it by mbrodersen on Friday June 17, 2022 @09:53PM (#31786662)
You clearly have strong opinions about things you don’t understand or have any experience with.
Re:The computers are fast, but you don't know it by pjvsvsrtrxc on Thursday June 16, 2022 @04:19PM (#31770489)
Yes, writing software in C/C++ is harder. It's a darn good thing most software is used much more frequently than it is written, isn't it?
Re:The computers are fast, but you don't know it by bena on Thursday June 16, 2022 @04:14PM (#31770427)
I kind of feel both statements.

I like writing things in python. It honestly feels like cheating at times. Being able to reduce things down to a list comprehension feels like wizardry.

I like having things written in C/C++. Because like every deep magic, there's a cost associated with it.

Re:The computers are fast, but you don't know it by tester756 on Thursday June 16, 2022 @04:08PM (#31770353)
Is performance inversely proportional to dev experience?

because what you wrote could be said about using C++ in the context of dev experience

10 compilers, IDEs, debuggers, package managers

and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware

I don't believe that this is the best we can get.

Re:The computers are fast, but you don't know it by jcelerier on Thursday June 16, 2022 @04:29PM (#31770607)
> and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware

I mean, that's the initial build.

Here's my compile-edit-run cycle in https://ossia.io which is nearing 400kloc, with a free example of performance profiling, I haven't found anything like this whenever I had to profile python. It's not LLVM-sized of course, but it's not a small project either, maybe in the medium-low C++ project size: https://streamable.com/o8p22f ; pretty much a couple seconds at most from keystroke to result, for a complete DAW which links against Qt, FFMPEG, LLVM, Boost and a few others. Notice also how my IDE kindly informs me of memory leaks and other funsies.

    C/C++ Header                      2212          29523          17227         200382
    C++                               1381          34060          13503         199259
Here's some additional tooling I'm developing - build times can be made as low as a few dozen milliseconds when one puts some work into making the correct API and using the tools correctly: https://www.youtube.com/watch?v=fMQvsqTDm3k
Re:The computers are fast, but you don't know it by pjvsvsrtrxc on Thursday June 16, 2022 @04:21PM (#31770510)
Huh?

"10 compilers, IDEs, debuggers, package managers" what are you talking about? (Virtually) No one uses ten different tools to build one application. I don't even know of any C++-specific package managers, although I do know of language-specific package managers for... oh, right, most scripting languages. And an IDE includes a compiler and a debugger, that's what makes it an IDE instead of a text editor.

"and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware" sure, if you're compiling something enormous and bloated... I'm not sure why you think that's an argument against debloating?

Re:The computers are fast, but you don't know it by tester756 on Thursday June 16, 2022 @05:11PM (#31771018)
>No one uses ten different tools to build one application.

I meant you have a lot of choices to make

Instead of having one strong standard which everyone uses, you have X of them which makes changing projects/companies harder, but for solid reason? I don't know.

>"and at the end of the day LLVM compiles 30min and uses tens of GBs of RAM on average hardware" sure, if you're compiling something enormous and bloated... I'm not sure why you think that's an argument against debloating?

I know that lines in repo aren't great way to compare those things, but

.NET Compiler Infrastructure:

20 587 028 lines of code in 17 440 files

LLVM:

45 673 398 lines of code in 116 784 files

The first one I built (restore+build) in 6mins and it used around 6-7GB of RAM

The second I'm not even trying because the last time I tried doing it on Windows it BSODed after using _whole_ ram (16GBs)

Re:The computers are fast, but you don't know it by archi42 on Friday June 17, 2022 @05:34AM (#31775949)
Compiling a large number of files on Windows is slow, no matter what language/compiler you use. It seems to be a problem with the program invocation, which takes "forever" on Windows. It's still fast for a human, but it's slow for a computer. Quite apt this comes up here ;-)

Source for claim: That's a problem we actually faced in the Windows CI at my old job. Our test suite invoked about 100k to 150k programs (our program plus a few 3rd party verification programs). In the Linux CI the whole thing ran reasonably fast, but the Windows CI took double as long. I don't recall the exact numbers, but if Windows incurs a 50ms overhead per program call you're looking at 1:20 (one hour twenty minutes) more runtime at 100k invocations.

Also I'm pretty sure I've built LLVM on 16GB memory. Took less than 10 minutes on a i7-2600. The number of files is a trade off: You can combine a bunch of small files into a large file to reduce the build time. You can even write a tool that does that automatically on every compile (and keeps sane debug info). But now incremental builds take longer, because even if you change only one small file, the combined file needs to be rebuild. That's a problem for virtually all compiled languages.

Re:The computers are fast, but you don't know it by tester756 on Friday June 17, 2022 @06:52AM (#31776393)
It's crazy that they have multiplied files count by 7 meanwhile the code just by 2

is it some C++ header file overhead? or they do something specific?

Re:The computers are fast, but you don't know it by archi42 on Monday June 20, 2022 @06:14AM (#31808473)
I can only guess, I am neither a LLVM nor a MSVC dev.

1. Compile times: If you have one file with 7000 LOC that and change one function in that file, the rebuild is slower than if you had 7 files with 1000 LOC instead.

2. Maintainability: Instead of putting a lot of code into one file, you put the code in multiple files for better maintainability. IIRC LLVM was FOSS from the beginning, so making it easy for lots of people to make many small contributions is important. I guess .NET was conceived as being internal to MS, so less people overall, but newcomers probably were assigned to a team for onboarding and then contributing to the project as part of that team. With other words: At MS you can call up the person or team responsible for that 10000 LOC monstrosity; but if all you got is a bunch of names with e-mail addresses pulled from the commit log, you might be in for a bad time.

3. Generated code: I don't know if either commit generated code into the repository. That can skew these numbers as well.

4. Header files can be a wild card, as it depends on how their written. Some people/projects just put the signatures in there and not too much details, others put the whole essays as docs for each {class, method, function, global} in there, making them huge.

For the record, by your stats .NET has 1180 LOC per file and LLVM 391 on average. That doesn't say a lot, the median would probably be better, or even a percentile graph. Broken down by type (header/definition vs. implementation). You might find that the distribution is similar and a few large outliers skew it (especially generated code). Or when looking at more, big projects you might find that these two are outliers. I can't say anything definite, and from an engineering perspective I think neither is "suspicious" or even bad.

My gut feeling says 700 would be a number I'd expect for a large project.

Re:The computers are fast, but you don't know it by jcelerier on Wednesday June 22, 2022 @04:20AM (#31833330)
> My gut feeling says 700 would be a number I'd expect for a large project.

aha, I remember when I was in class, the absolute rule our teachers gave us was no more than 200 lines per file

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:47PM (#31770787)
I assume the parent was talking about the fragmentation in the ecosystem (fair point, especially regarding package management landscape and build tooling), but it's unclear.
Re:The computers are fast, but you don't know it by optimalsolver on Thursday June 16, 2022 @05:52PM (#31771444)
>I don't even know of any C++-specific package managers

https://conan.io/

Re:The computers are fast, but you don't know it by bhauer on Thursday June 16, 2022 @04:18PM (#31770479)
> Is performance inversely proportional to dev experience?

No. I feel there is great developer experience in many high performance languages: Java, C#, Rust, Go, etc.

In fact, for my personal tastes, I find these languages more ergonomic than many popular dynamic languages. Though I will admit that one thing that I find ergonomic is a language that lifts the performance headroom above my head so that I'm not constantly bumping my head on the ceiling.

Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:51PM (#31771985)
You haven’t touched a C++ toolchain in the last decade, have you?
Re:The computers are fast, but you don't know it by spc476 on Thursday June 16, 2022 @05:31PM (#31771228)
TCC is a fast compiler. So fast, that at one time, one could use it to boot Linux from source code! But there's a downside: the code is produces is slow. There's no optimization done. None. So the trade off seems to be: compile fast but slow program, or compile slow but fast program.
Re:The computers are fast, but you don't know it by scarmig on Thursday June 16, 2022 @05:56PM (#31771487)
The trade-off is more of a gradient: e.g. PGO allows an instrumented binary to collect runtime statistics and then use those to optimize hot paths for future build cycles.
Re:The computers are fast, but you don't know it by tester756 on Thursday June 16, 2022 @06:14PM (#31771675)
is this actually this binary?

I mean what if there are features that take significant % of whole time

What if getting rid of them could decrease perf by e.g 4%, but also decrease comp. time by 30%

would it be worth?

Re:The computers are fast, but you don't know it by michaelchisari on Thursday June 16, 2022 @04:18PM (#31770471)
I wish product designers took performance into consideration when they designed applications. Engineers can optimize until their fingers fall off, but if the application isn't designed with efficiency in mind (and willing to make trade-offs in order to achieve that), we'll probably just end up right back in the same place.

And a product which is designed inefficiently where the engineer has figured out clever ways to get it to be more performant is most likely a product that is more complicated under the hood than it would be if performance were a design goal in the first place.

Re:The computers are fast, but you don't know it by kllrnohj on Thursday June 16, 2022 @07:21PM (#31772206)
Rather than bare C something like C++, Rust, or even Haskell would be better. C isn't the fastest, especially not with normal code. C++ templates get a bad rep, but if you want to go fast they are extremely hard to beat.

Also those languages show you don't actually have to give up modern features or even that much convenience in order to get blazing fast speeds.

Re:The computers are fast, but you don't know it by necovek on Friday June 17, 2022 @05:43AM (#31776005)
In a sense, knowing this can also hurt you.

At all my recent jobs, I grow frustrated with how slow running a single unit test is locally on a codebase. We are talking 5+ seconds for even the most trivial of trivial unit tests (say, purely functional arithmetic unit test).

And this is even with dynamic languages like Python (you see pytest reporting how your unit test completed in 0.00s, and wall time is 7s).

And then I get grumpy if they don't let me go and fix it because I am the only one who is that annoyed with this :D

Re:The computers are fast, but you don't know it by hinkley on Saturday June 18, 2022 @01:52AM (#31787539)
How on earth are you getting 5 seconds for simple tests? Simple tests should be running in 8ms, and those are my 2015 numbers that I've been too lazy to update.
Re:The computers are fast, but you don't know it by necovek on Saturday June 18, 2022 @03:28AM (#31787919)
Have you worked on a recent idiomatic development setup (dockerised local development, top level imports of everything and plenty of setup at the top level too, people unfamiliar with how to manage .pyc files so they simply disable them...)?

Common libraries like requests or sqlalchemy take 300-500ms to import (eg. try `time python3 -c 'import requests'` and contrast just `time python3 -c ''` which is python startup overhead).

As I said, tests run in sub 10ms, but from issuing pytest to completion it's usually 5-15s.

Re:The computers are fast, but you don't know it by hinkley on Saturday June 18, 2022 @04:24PM (#31793491)
Ah, I see, so the setup time is very slow. I don't work in python much but I've worked in a few other languages with slow startup, and amortization is your friend. It's hard though when you have a small module with 'only' 300 tests and your test is 6ms of code that works out to 40ms once setup and teardown are included. I haven't had many opportunities to have the "well maybe you should be making bigger modules" conversation but I am ready for that moment to arise.

This is usually the point at which I pull out a 'watch' implementation, since the 5 seconds it's going to take me to switch windows and hit 'up' the right number of times counts too, if we're comparing apples to apples.

That said, one of the last times I had a unit testing mentor, I walked into a project that ran 3800 tests in about 7 seconds, and then started poking around trying to figure out who was materially responsible. (He didn't know much more than me from an implementation standpoint, but boy was he good at selling people on test quality.) If that had been 20 seconds it would have still been lovely, but it wouldn't have grabbed my attention quite as much.

Re:The computers are fast, but you don't know it by rasz on Tuesday June 21, 2022 @01:10AM (#31820134)
Last time I played with python adding one empty line to my source code was slowing execution my ~8ms.
Re:The computers are fast, but you don't know it by fullstackchris on Thursday June 16, 2022 @08:19PM (#31772608)
While I'll take a bite at this, I think it's also fair to say how poorly portable C is. Can an mobile or web engineer quickly take some C code and use it in their stack somehow? I would guess not. While it's indeed an important lesson to see the speed of some of these 'close to the metal' languages, the question of how practical they are to use is a different question.
Re:The computers are fast, but you don't know it by loup-vaillant on Friday June 17, 2022 @05:21AM (#31775863)
There is a class of C code that can be made extremely portable: pure computations. This allows you to write self contained code with zero dependencies, and if you're willing to give up on SIMD you can stick to fully conforming C99.

It's not applicable for everything, but we do have some niches where it comes in handy: cryptographic libraries (I've written one), parsers and encoders of all kind, compilers…

For instance can a mobile on web engineer quickly take TweetNaCl or Monocypher and use it in their stack? Yes. They may need to write some bindings themselves, but if they can run C code at all it's fairly trivial.

Re:The computers are fast, but you don't know it by Aeolun on Friday June 17, 2022 @01:41AM (#31774474)
This was about my experience switching from webpack to ESBuild for Javascript. Why do incremental builds if rebuilding the whole thing takes just 2s (as opposed to 90+ with webpack).
Re:The computers are fast, but you don't know it by nyanpasu64 on Thursday June 16, 2022 @09:47PM (#31773199)
I wish C++ compilers written in C++ were blazing fast too.
Re:The computers are fast, but you don't know it by kllrnohj on Friday June 17, 2022 @02:26AM (#31774725)
They are. They've just chosen to spend all their speed gains on more optimization passes and static analysis, to produce ever faster outputs than to produce an output faster.
Re:The computers are fast, but you don't know it by wruza on Friday June 17, 2022 @03:36AM (#31775195)
Their fundamental model is one translation unit per time, while developers decided that writing all library code in headers is a good idea. Which makes them parse and DCE literally kilometers of mostly irrelevant code again and again. You’re not wrong, but it’s not the complete point. C++ development is slow as a whole, and compilers/standards do nothing to fix that. It’s a kind of F1 engine in a tractor situation.
Re:The computers are fast, but you don't know it by munificent on Friday June 17, 2022 @12:08PM (#31780276)
> while developers decided that writing all library code in headers is a good idea.

It wasn't developers who designed C++'s template model which requires generic code to be fully defined in header files.

Inheriting C's textual include file based "module" system and then bolting compile-time specialized generics is a choice the C++ committee made, not C++ users. It was probably the right choice given C++'s many very difficult constraints, but that's what directly leads to huge compile times, not dumb C++ users.

Re:The computers are fast, but you don't know it by gpderetta on Friday June 17, 2022 @06:05AM (#31776122)
> and compilers/standards do nothing to fix that

C++20 finally standardized modules. Whether they will improve things significantly is still anyone guess.

Re:The computers are fast, but you don't know it by latenightcoding on Thursday June 16, 2022 @04:42PM (#31770742)
off topic but I initially didn't notice your username but the second I read "I wrote my own template language in Dart" I knew who it was.
Re:The computers are fast, but you don't know it by munificent on Friday June 17, 2022 @12:22PM (#31780502)
Haha, yes, I definitely realized I was doing some extremely on-brand yak shaving when I did it.
Re:The computers are fast, but you don't know it by zozbot234 on Thursday June 16, 2022 @04:25PM (#31770554)
Please don't write programs in bare C. Use Go if you're looking for something very simple and fast-enough for most uses; it's even memory safe as long as you avoid shared-state concurrency.
Re:The computers are fast, but you don't know it by staticassertion on Thursday June 16, 2022 @04:55PM (#31770874)
Unqualified "fast enough" is pretty much exactly the problem being pointed out. Most developers have no idea what "fast" is let alone "fast enough". If they were taught to benchmark at with a lower level language, see what adding different abstractions causes, that would help a ton.

I would personally suggest C++ though because there is such a huge amount of knowledge around performance and abstraction in that community - wonderful conference talks and blog posts to learn from.

Re:The computers are fast, but you don't know it by shadowofneptune on Thursday June 16, 2022 @05:29PM (#31771208)
Go comes from a different school of compiler design where the code generation is decent in most cases, but struggles with calculations and more specific patterns. Delphi is a similar compiler. Looking at benchmarks, the performance is only a few times worse than optimized C. That's on par with the most optimized JITed languages like Java, while being overall a much simpler compiler. I feel it is is fair to say 'good enough' in this situation.
Re:The computers are fast, but you don't know it by zozbot234 on Thursday June 16, 2022 @05:01PM (#31770938)
It's not an "unqualified" claim, Go really is fast enough compared to the likes of Python and Ruby. I'm not saying that rewriting a Go program in a faster language (C/C++/Rust) can't sometimes be effective, but that's due to special circumstances - it's not something that generalizes to any and all programs.
Re:The computers are fast, but you don't know it by staticassertion on Thursday June 16, 2022 @06:25PM (#31771756)
"Fast enough" is inherently unqualified since what "enough" is is going to be case specific.
Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @04:32PM (#31770641)
Please don't write programs in go. Sure it looks awesome on the surface but it's a nightmare when you get a null pointer panic in a 3rd party library.

Instead use Rust.

See here for more info:

https://getstream.io/blog/fixing-the-billion-dollar-mistake-...

Re:The computers are fast, but you don't know it by AnimalMuppet on Thursday June 16, 2022 @06:34PM (#31771838)
You've obviously been burned by null pointers (probably not just once). And you think they are a problem, and you're right. And you think they are a mistake, and you could be right about that, too.

But they're not the only problem. Writing async network servers can be a problem, too. Go helps a lot with that problem. If for your situation it helps more with that than it hurts with nulls, then it can be a rational choice.

And, don't assume that go must be a bad choice for all programmers, in all situations. It's not.

Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @06:56PM (#31772037)
And it's certainly not perfect in writing async network servers. It adds new concurrency bug types:

https://songlh.github.io/paper/go-study.pdf

Re:The computers are fast, but you don't know it by lmm on Friday June 17, 2022 @12:35AM (#31774158)
> But they're not the only problem.

No, but they're literally more than 50% of bugs, in my experience, so they're a bigger problem than all your other problems put together.

Re:The computers are fast, but you don't know it by michaelsshaw on Thursday June 16, 2022 @04:35PM (#31770666)
Nothing wrong with any of these languages, especially C. It's been around since the early 70s and is not going anywhere. There's a very good reason it (and to an extent C++) is still is the default language for doing a lot of things since everyone understands it.
Re:The computers are fast, but you don't know it by KronisLV on Thursday June 16, 2022 @04:39PM (#31770715)
C and C++ both have excellent library support, perhaps the best interop of any language out there and platform support that cannot be beat.

That said, they're also challenging to use for the "average" (median) developer who'd end up creating code that is error-prone and would probably have memory leaks sooner or later.

Thus, unless you have a good reason (of which, admittedly, there are plenty) to use C or C++, something that holds your hand a bit more might be a reasonable choice for many people out there.

Go is a decent choice, because of a fairly shallow learning curve and not too much complexity, while having good library support and decent platform support.

Rust is a safer choice, but at the expense of needing to spend a non-insignificant amount of time learning the language, even though the compiler is pretty good at being helpful too.

Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @04:55PM (#31770876)
> That said, they're also challenging to use for the "average" (median) developer who'd end up creating code that is error-prone and would probably have memory leaks sooner or later.

Many of the most highly credentialed, veteran C developers have said they can't write secure C code. Food for thought.

> Go is a decent choice, because of a fairly shallow learning curve and not too much complexity, while having good library support and decent platform support. Rust is a safer choice, but at the expense of needing to spend a non-insignificant amount of time learning the language, even though the compiler is pretty good at being helpful too.

Go doesn't have the strongest static guarantees, but it does provide a decent amount of static guarantees while also keeping the iteration cycle to a minimum. Languages like Rust have significantly longer iteration cycles, such that you can very likely ship sooner with Go at similar quality levels (time savings can go into catching bugs, including bugs which Rust's static analysis can't catch, such as race conditions). Moreover, I've had a few experiences where I got so in-the-weeds trying to pacify Rust's borrow-checker that I overlooked relatively straightforward bugs that I almost certainly would've caught in a less-tedious languages--sometimes static analysis can be distracting and in that respect, harm quality (I don't think this a big effect, but it's not something I've seen much discussion about).

Re:The computers are fast, but you don't know it by _gabe_ on Thursday June 16, 2022 @05:37PM (#31771301)
> secure C code.

There is unsecure code hidden in every project that uses any programming language ;)

I get what you're saying here, you're specifically talking about security vulnerabilities from memory related errors. I honestly wonder how many of these security vulnerabilities are truly issues that never would have come up in a more "secure" language like Java, or if the vulnerabilities would have just surfaced in a different manner.

In other words, we're constantly told C and C++ are unsafe languages they should never be used and blah blah blah. How much of this is because of the fact that C has been around since the 1970s, so its had a lot more time to rack up large apps with security vulnerabilities, whereas most of the new recommended languages to replace C and C++ have been around since the late 90s. In another 20 years will we be saying the same thing about java that people say about C and C++? And will we be telling people to switch to the latest and greatest because Java is "unsafe"? Are these errors due to the language, or is it because we will always have attackers looking for vulnerabilities that will always exist because programmers are fallible and write buggy code?

Re:The computers are fast, but you don't know it by nequo on Thursday June 16, 2022 @06:57PM (#31772046)
> In another 20 years will we be saying the same thing about java that people say about C and C++? And will we be telling people to switch to the latest and greatest because Java is "unsafe"?

As long as the vulnerability types that cause trouble in language B are a superset of those that cause trouble in language C, it makes sense to recommend moving from B to C for safety reasons.

This is true even if there is a language A that is even worse and in the absence of language C, we recommended moving from A to B. Code written in A will be worse in expectation than code written in B than code written in C.

Re:The computers are fast, but you don't know it by jcranmer on Thursday June 16, 2022 @06:49PM (#31771977)
> I honestly wonder how many of these security vulnerabilities are truly issues that never would have come up in a more "secure" language like Java, or if the vulnerabilities would have just surfaced in a different manner.

Memory safety vulnerabilities basically boil down to following causes: null pointer dereferences, use-after-free (/dangling stack pointers), uninitialized memory, array out-of-bounds, and type confusion. Now, strictly speaking, in a memory-safe languages, you're guaranteed not to get uncontrollable behavior in any of these cases, but if the result is a thrown exception or panic or similar, your program is still crashing. And I think for your purposes, such a crash isn't meaningfully better than C's well-things-are-going-haywire.

That said, use-after-free and uninitialized memory vulnerabilities are completely impossible in a GC language--you're not going to even get a controlled crash. In a language like Rust or even C++ in some cases, these issues are effectively mitigated to the point where I'm able to trust that it's not the cause of anything I'm seeing. Null-pointer dereferences are not effectively mitigated against in Java, but in Rust (which has nullability as part of the type), it does end up being effectively mitigated. This does leave out-of-bounds and type confusion as two errors that are not effectively mitigated by even safe languages, although they might end up being safer in practice.

Re:The computers are fast, but you don't know it by kaba0 on Friday June 17, 2022 @03:58PM (#31783465)
It depends on what you mean by mitigated. Java mitigates null pointers by deterministically raising an exception (as well as out of range situations), but indeed it doesn’t handle them at compile time (though the latter can’t even be solved in the general case, and only with dependent types)
Re:The computers are fast, but you don't know it by throwaway894345 on Thursday June 16, 2022 @06:35PM (#31771840)
> There is unsecure code hidden in every project that uses any programming language ;)

Security isn't a binary :) Two insecure code bases can have different degrees of insecurity.

> I honestly wonder how many of these security vulnerabilities are truly issues that never would have come up in a more "secure" language like Java, or if the vulnerabilities would have just surfaced in a different manner.

I don't know how memory safety vulns could manifest differently in Java or Rust.

> In other words, we're constantly told C and C++ are unsafe languages they should never be used and blah blah blah. How much of this is because of the fact that C has been around since the 1970s, so its had a lot more time to rack up large apps with security vulnerabilities

That doesn't address the veteran C programmers who say they can't reliably write secure C code (that's new code, not 50 year old code).

> Are these errors due to the language, or is it because we will always have attackers looking for vulnerabilities that will always exist because programmers are fallible and write buggy code?

A memory safe language can't have memory safety vulnerabilities (of course, most "memory safe" languages have the ability to opt out of memory safety for certain small sections, and maybe 0.5% of code written in these languages is memory-unsafe, but that's still a whole lot less than the ~100% of C and C++ code).

Of course, there are other classes of errors that Java, Rust, Go, etc can't preclude with much more efficacy than C or C++, but eliminating entire classes of vulnerabilities is a pretty compelling reason to avoid C and C++ for a whole lot of code if one can help it (and increasingly one can help it).

Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @02:32AM (#31774762)
Languages like NEWP are around since 1961 and don't suffer from C exploits.

Why does Unisys still sell ClearPath MCP?

For agencies where security is top priority above anything else.

Re:The computers are fast, but you don't know it by megous on Friday June 17, 2022 @07:36AM (#31776691)
Many PHP and JS programmers can't write secure code either.
Re:The computers are fast, but you don't know it by throwaway894345 on Friday June 17, 2022 @09:35AM (#31777922)
First of all, you’re comparing “most PHP and JS programmers” with veteran C programmers, and secondly most PHP and JS programmers can write code which is secure against memory-based exploits.
Re:The computers are fast, but you don't know it by megous on Monday June 20, 2022 @04:18AM (#31807638)
Which has not stopped them from allowing compromise of millions of servers.
Re:The computers are fast, but you don't know it by bb88 on Thursday June 16, 2022 @04:45PM (#31770770)
> perhaps the best interop of any language out there and platform support that cannot be beat.

Disagree here. The C++ ABI has pretty much been terrible for the last 20 years.

C is fine in this regard though.

Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @02:33AM (#31774766)
Re:The computers are fast, but you don't know it by pjmlp on Friday June 17, 2022 @02:30AM (#31774751)
One reason is historical baggage and sinergy.

It is easier to just pick an existing library and deal with security flaws, than trying to ramp up an ecosystem from scratch, unless one has the backing of a multinational pumping up development.

Re:The computers are fast, but you don't know it by tomcam on Thursday June 16, 2022 @04:35PM (#31770664)
Or, you know, whatever the fuck language you care to use.
Re:The computers are fast, but you don't know it by kaba0 on Thursday June 16, 2022 @06:55PM (#31772034)
If Go is “fast enough”, then so is Java, C#, JS, Haskell, and a litany of other managed languages.
Re:The computers are fast, but you don't know it by lmm on Friday June 17, 2022 @12:33AM (#31774150)
Yes. For some reason programming culture repeatedly fails to realise that if you want to group languages into two buckets by performance with one being "like C" and the other being "like Python" then all the languages you list (except maybe JS) belong in the "like C" bucket.
Re:The computers are fast, but you don't know it by skybrian on Thursday June 16, 2022 @04:45PM (#31770769)
I mean, he just explained that after rewriting his program in Dart, it was fast enough? That's not really the point here.

On the other hand, I tried writing a Wren interpreter in Go and it was considerably slower than the C version. Even programming languages that are usually pretty fast aren't always fast, and interpreter inner loops are a weak spot for Go.

Re:The computers are fast, but you don't know it by zozbot234 on Thursday June 16, 2022 @04:55PM (#31770868)
> I mean, he just explained that after rewriting his program in Dart, it was fast enough?

Yes, and that makes his C advocacy even less sensible. Dart is a perfectly fine language, even though it seems to be a bit underused compared to others.

Re:The computers are fast, but you don't know it by munificent on Friday June 17, 2022 @12:10PM (#31780304)
I didn't advocate that anyone ship production code written in C.

I advocated that people write programs in C and run them to see how fast executables can startup and run.

(Dart isn't great for that because while its runtime performance is pretty fantastic, it does still take a hit on startup because it's a VM with a fairly large core library and runtime system.)

Re:The computers are fast, but you don't know it by skybrian on Thursday June 16, 2022 @05:30PM (#31771218)
Spending "a little time writing some programs in C" is not the same as advocating that people write most of their code in C, or that you use it in production.

Maybe try reading Crafting Interpreters, half of which is in Java and half in C.

http://craftinginterpreters.com/

Re:The computers are fast, but you don't know it by cozzyd on Thursday June 16, 2022 @05:21PM (#31771126)
If you want to write something you can use from any language, C is still the best choice...
Re:The computers are fast, but you don't know it by tomcam on Thursday June 16, 2022 @04:34PM (#31770654)
Some of us know how to program. Some of us know the fundamentals.
Re:The computers are fast, but you don't know it by dylan604 on Thursday June 16, 2022 @04:56PM (#31770877)
Fewer know both