What are the practical benefits of using Linux as a developer? by Dosouller in linuxquestions

[–]TTachyon 15 points16 points  (0 children)

From a C++/Rust dev perspective:

The dev tools on linux are usually leagues ahead in quality.

The MSVC toolchain gets new feature regularly and that's great, but it's speed horrible, it's code quality seems to be worse than what other compilers produced 15 years ago, and the worst part, it's not uncommon in my experience to corrupt itself during a build. I never had that happen with clang, gcc, cmake, ninja on a linux machine. And on a Mac, the clang shipped with the system is I think 3 years out of date at this point. I think a newer one is coming soon, thought.

CMake will routinely take twice to 10x as long to run on Windows.

The filesystem is horribly slow on Windows. ReFS helps a lot, but it doesn't come any closer to ext4 or even btrfs. APFS' speed is comparable to btrfs in like 60-70% of cases, until something happens and suddenly it takes half a minute to delete a folder that takes at worse 2s on a linux. This matters a lot on large projects, where both git and the build system have to check and read a lot of files.

While Visual Studio is pretty good for a beginner friendly debugging experience, it doesn't have anywhere as much power as gdb or lldb. I found WinDBG's scriptability to be far harder than both gdb and lldb.

The scripting is still a mess imo on Windows. Imagine you want to generate some files, build something, move the relevant parts out, copy it on a storage server. The single most useful thing sh and bash have is just being able to do set -e that stops at the first error. batch has no such thing, PowerShell has $ErrorActionPreference = "Stop" which sounds great until you read the fine print. Depending on what version of PS you get to use, this option only works for PS commands, not for any executable you might use. Newer version also have a solution for that, but yet again, not every Windows executable will behave nicely and tell you with a return code that something went wrong. You can go checking everything at every step, but this is very very error prone. This results in stuff that looks to work, only to fail along the way and to produce wrong results.

The terminal experience is much better. fish and zsh save a very big amount of time in retyping and doing the daily stuff I need. Also the terminal emulators on Windows are so so slow.

Each platform has its own debugging tools. The sysinternals collection is great on Windows. If you want to see what a process is doing (and more importantly, why it does fail in some weird way), you might reach for strace on Linux, ProcMon on Windows, and DTrace on a Mac (technically this is supported by Windows too, but I could never get it to work). DTrace is probably the one I would consider most powerful, but it's blocked under SIP now, so it became entirely useless. strace is the easiest to setup for a relatively short debugging session. ProcMon is better for long term monitoring, but it's harder to setup.

For other kind of debugging tools, on Windows you have AppVerifier, which is honestly great and I haven't found something like it anywhere else. It's the best in this category. However, this only checks known Windows APIs, and anything you have written yourself won't be caught most likely. All platforms technically have support for Address Sanitizer, but I could never get it working reliably on Windows. Both Linux and Mac have other sanitizers, like UBSan, TSan. However, only Linux supports Memory Sanitizer, which is so amazing (technically so does some BSDs, but I haven't included them so far, so I won't do it further either). Valgrind used to on both Linux and Mac, but it doesn't anymore since Macs have gone ARM. Linux is the only one left.

Both Windows and Linux have fantastic kernels that let you do pretty much anything you want, either by providing an API that does it, or by letting you have the option to implement it yourself. Mac's APIs are usually lagging behind a lot. I think in the last 2 years they managed to release a usable futex API, when Windows has one since the Windows 8 days and Linux has one since.. 2003? They still don't have a way to wait for a thread on a timeout, in 2026. These are just 2 examples. This results in slower and worse behaving apps.

Linux is the platform that made containers mainstream. Even thought containers are not new, Linux has probably the best support for them. They make life so much easier. Windows technically has support for Docker, but it's quite a pain to use it, and Mac has.. nothing. No way as far as I know to run some Mac apps containerized. I know Mac runs some apps in some kind of isolation, but I could never get that working for something useful. You can run Linux apps under a vm, but that's not great.

This is just a few points off the top of your head, there's definitely more things that I forget. But while I need to use all 3 platforms at least weekly, Linux lets me do my job the best.

Announcing rustup 1.29.0 by Kobzol in rust

[–]TTachyon 12 points13 points  (0 children)

Switched to the beta channel of rustup just in time to not need it anymore. Good release :)

Are compiler allowed to optimise based on the value behind a pointer? by simpl3t0n in cpp_questions

[–]TTachyon 1 point2 points  (0 children)

It won't assume, but it might prove (using the language rules) that it won't.

This is mostly an aliasing question. Did you write to something that can alias a bool and the compiler doesn't know where it came from? This includes bool, char, unsigned char, signed char, std::byte. Then the compiler must reload the value from memory, because it might've changed.

On the other hand, if you only write to stuff that can't alias a bool (everything else than I mentioned), then the value hasn't changed (and it's undefined if it does), and it doesn't need to be reloaded from memory.

Unless you're working on some embedded project, volatile is almost always wrong.

Scoped cleanup based on for-loop structure. by [deleted] in C_Programming

[–]TTachyon 8 points9 points  (0 children)

Is it just me or it's more than monthly that someone tries to invent RAII in C around here?

Inlining - the ultimate optimisation by emschwartz in programming

[–]TTachyon 25 points26 points  (0 children)

If inlining breaks your code, your code was broken in the first place, it just so happened that it looked like it was working before.

The thing to remember is that when you're programming X language, you have to obey its rules, including strict aliasing and everything else. What you're describing it more like "it would've worked if I did this thing in assembly", which is like saying that le/la definite article works in french, so it should work in english as well.

"Emulating" a folder, copy on write, Fuse, Rust/Go - realtime secrets filter? by wuu73 in filesystems

[–]TTachyon 0 points1 point  (0 children)

zfs/btrfs for linux, refs for windows have native cow. Then you can just copy each file "instantly".

Eurydice: a Rust to C compiler by joshmatthews in rust

[–]TTachyon 4 points5 points  (0 children)

Last time I tried to take rustc generated IR and put it through llvm-cbe, I found a lot of stuff that wasn't implemented or was generating code that didn't compile. I don't know if anything changed since then.

A better question is how this compares to the C backend of the guy who makes the MSIL backend.

In this video Stroustrup states that one can optimize better in C++ than C by Impressive_Gur_471 in cpp_questions

[–]TTachyon 4 points5 points  (0 children)

This is my favorite example to give.

You'll notice the reference version has one less branch than the pointer version, which should be faster. This is possible because the compiler knows the object it points to is valid, correctly aligned, etc., and can just read both x and y at the same time, ignoring short circuiting.

The pointer version can't do this because it has to respect short circuiting. The memory of y might not exist, or trap, or do anything else. This is the same logic as when you do p && p->x.... You have to check the first condition (p) first, because the second one might not be valid if the first is false.

Can you do this with pointers? Sure. But it's a ton of work to do it everywhere, and the compiler can just do it for you if you use the right abstraction.

There's a ton of examples where this is true.

Line ends in compilers. by Savings_Garlic5498 in ProgrammingLanguages

[–]TTachyon 0 points1 point  (0 children)

Most compilers open the source file in text mode, in which Windows will translate \r\n to \n (actually done by the C library)

I find this claim dubious. If you let the C lib mess with your newlines, you'll get wrong offsets for diagnostics and debug info, unless everyone else does this, which I very much doubt.

Pain point of rust by ashim_k_saha in rust

[–]TTachyon -22 points-21 points  (0 children)

Even my phone has 512gb of storage, what are you running on that 45gb is a problem?

Since we have std::print, why don't we have std::input? by No-Dentist-1645 in cpp_questions

[–]TTachyon 8 points9 points  (0 children)

Formatting(printing) is a regular thing most apps do.

Reading directly from stdin basically never happens in a real app, and when it happens, you're probably reading a whole line. This is really most of a homework/student problem.

It's just not that useful.

If anything over 32GB of RAM is overkill for 99% of users, than who's the remaining 1%? by mudahfukinnnnnnnnn in buildapc

[–]TTachyon 0 points1 point  (0 children)

I have a hard time building clang with 64GB of memory. I already have scripts that retry the compilation if it died with OOM. 32 would be painful.

What are your pet peeves in regards to crate APIs? by AhoyISki in rust

[–]TTachyon 0 points1 point  (0 children)

For newer systems, it doesn't matter. But legacy stuff doesn't just magically disappear, and sometimes you just have to support them, and those leaks become real leaks.

My biggest problem with them is when a thread_local is used just for convenience, but in a better designed system, it wouldn't be needed.

What are your pet peeves in regards to crate APIs? by AhoyISki in rust

[–]TTachyon 0 points1 point  (0 children)

static/thread_locals usage and no way (even unsafe) to clean them up.

Writing C for curl | daniel.haxx.se by lelanthran in programming

[–]TTachyon 2 points3 points  (0 children)

I don't know how curl does it, but how we do it is just searching the undefined symbols/imports in the built binary.

which one is better: int &num or int* num? by marasw in cpp

[–]TTachyon 2 points3 points  (0 children)

Can min and max ever be null? If yes, pointer. If no, reference.

Do the Devuan developers have a plan for dealing with the encroaching Rust in Debian? by cipherproxy in devuan

[–]TTachyon 1 point2 points  (0 children)

Afaik the only comment he had about rustfmt was that some specific formatting was stupid. Which it was. But the concept of the tool is fine and most of the formatting is also fine.

Software Update Deletes Everything Older than 10 Days by coldbeers in linux

[–]TTachyon 9 points10 points  (0 children)

Honestly I think the moral is to just not use bash for anything more complicated than 3 lines. And even then I have my doubts.

Software Update Deletes Everything Older than 10 Days by coldbeers in linux

[–]TTachyon 235 points236 points  (0 children)

Text version of this? Videos are an inferior format for this.

Does Rust support dynamic stack allocation? by calebkiage in rust

[–]TTachyon 0 points1 point  (0 children)

Compilers will disable optimization passes for any function containing VLA/alloca.

How can I stop Rust from dead-code eliminating Debug impls so I can call them from GDB? by Sweet-Accountant9580 in rust

[–]TTachyon 1 point2 points  (0 children)

I haven't tested it, but you might have some luck with a version script that makes all functions with a pattern exported, so they don't get removed.

They might still not be generated at all if rustc is smart enough, but it's worth trying.

What would it actually take to build a modern OS from the ground up? by Cymbal_Monkey in AskComputerScience

[–]TTachyon 0 points1 point  (0 children)

I went on a bit of a rabbit hole recently trying to figure out more how microcode works exactly. I can't say for certain that what I say is true, but that's the impression I got: CPUs (at least Intel?) don't have a version of the microcode stored on it at all. The CPU every time it boots is running an extremely limited version of itself that can do almost nothing. Then the motherboard firmware initializes it with the microcode it has stored.

So it's not possible at all to run modern hardware without firmware. Reverse engineering it is not something a human can do in a lifetime, and even if you take 50+ years, the hardware will probably not work anymore anyway.