News for hackers. Stuff that matters.
Re:“C is how the computer works” is a dangerous mindset for ... by stiray on Tuesday March 31, 2020 @12:36PM (#22739342)
What is profoundly pissing me off are bunch of hipsters on the internet that are using xyz language and are constantly trying to compare everything to C. We are faster, we are better, we are more portable, we have JIT, we have reflection... and so on.

Who cares what your tool for solving the problem is. Use Java, use JS, use python, go, rust... whatever suits for the task. Why do you want to compare yourself to C. Just stop it. No one with enough expirience in coding will ever care what language you have used to acomplish the task. Unless the task is going to be purely written, slow, buggy, CPU consuming, will have security issues and so on. This can be acomplished with half-baked (I hate the expression, but sorry) coding monkey in any language. Why do you even care about C. It doesnt matter, all that are complaining about it in whatever way possible or compare to it, will probably never be involved in a task where C excels, so why bother?

---

jeffdavis: the problem is that people would like to use wrong tool for the job. And the fact that they cant frustrates them, blaming everything else except the fact that they picked the wrong tool. As you need expirience for picking the right tool. A lot of expirience or rather beeing fluent in all the tools. Which makes it a problem if you dont dedicate a lot of time to this.

---

jeffdavis #2: > choosing the wrong tool really is a great way to understand your tools and the problem more deeply.

YES! Exactly! I did mistakes, a lot of them, like pragma packing the structure and send it to system on other side of network in other endianness. Overwritting EIP number of times before I understood it. Or best one, translating command.com to my language using edit :D Used wrong call convention. But my goal was always to understand assembler. To understand C. To understand C++. And I have made quite a lot of code in all 3. Then learnt any language that crossed my way and it looked like interesting (Rust is still on my list) and used each in at least one project, hobby or not. Now everyone learns one or two languages, without any background knowledge and then starts to preach it, prove that language written in X is faster than language that X is written in and so on. Who cares! It makes me puke.

Re:“C is how the computer works” is a dangerous mindset for ... by jeffdavis on Tuesday March 31, 2020 @01:20PM (#22739871)
The "right tool for the job" is a myth (EDIT: exaggerating; clearly it applies in some cases). Languages don't work together very well, so you need huge, thick boundaries between them, such as serialization/deserialization. Data types don't match up, GCs require special data formats and don't line up with the GCs of other languages, other runtime weirdness, etc. At minimum, you need lots of copying/transformation of the data.

Have a gnarly problem in a Python program that Haskell would be perfect for? Too bad. You'll spend more time figuring out how to transform the data and get the Python code to call into Haskell than you'll save by using the right tool. And in the process, the overhead, complexity, and bugs introduced in this process turn the right tool into the wrong tool.

And that's the reason why C is so important. It actually does work with pretty much any language, because it has a defined ABI, simple data types, minimal runtime, can work on any data formats unmodified, no GC. Very few languages have this superpower.

C++ mostly has that superpower, but some features don't entirely work with unmodified structures (RTTI and virtual functions both require adding magical fields to the class structure). Rust seems to have this superpower (does dynamic dispatch a different way than C++, so can always work on unmodified structures).

The JVM is an interesting case and the ecosystem of languages built on it do work better together because they have the exact same runtime (GC, etc.).

To summarize: we'd all like to use the right tool for the job. But we can't, except for the languages that go out of their way to make this effective, and that list of languages is very short.

Re:“C is how the computer works” is a dangerous mindset for ... by ChrisSD on Tuesday March 31, 2020 @03:54PM (#22741760)
To be precise, C does not have a defined ABI (the spec goes out of its way to avoid this). Platforms (OS+Arch) define a C ABI for their own tools. Since this ABI is required to interop with the OS APIs, this will usually become the de-facto standard for the platform.

This might seem like nitpicking but it's an important distinction because you can't assume that C data structures can be passed between different platforms (e.g. over a network or even stored in a filesystem).

Re:“C is how the computer works” is a dangerous mindset for ... by jeffdavis on Tuesday March 31, 2020 @06:02PM (#22743162)
What is the right way to say that without sounding too pedantic every time? "Most platforms define a stable C ABI"?
Re:“C is how the computer works” is a dangerous mindset for ... by pjmlp on Wednesday April 01, 2020 @03:13AM (#22746445)
The only platforms that define a stable C ABI are those whose OS is written in C and exposes a C API to userspace.

Symbian did not had a C ABI for example, nor do mainframes, in ChromeOS or Android you also don't have a C ABI exposed to userspace, in Windows a C ABI also won't help you much if you need to speak COM or now UWP.

Re:“C is how the computer works” is a dangerous mindset for ... by sseagull on Tuesday March 31, 2020 @01:56PM (#22740348)
This really needs to be said more. For those of us not in web devel or microservices, the lower level of coupling between components really makes using multiple languages a pain. Plus, you have to learn all those languages -- sometimes I just want to actually get stuff done.

I consider it significant code smell when a project has multiple languages, particularly when each language seems tied to a particular developer.

Re:“C is how the computer works” is a dangerous mindset for ... by lliamander on Tuesday March 31, 2020 @03:11PM (#22741276)
A really thought-provoking argument. I suppose that when it comes to choosing "the right tool" the important thing is to optimize globally across the problems that your organization will be solving.

But if you want to be able to optimize both globally and locally, well that's just an engineering problem!

Two examples spring to mind:

1. Lisp. Lisp's metaprogramming facilities allow you to build the language into the specialized tools that you need, while still having the common runtime and base language.

2. Unix. There a hundreds (possibly even thousands) of little programs running on my Linux machine written in probably dozens of languages. For the most part, I have no idea (nor do I care) what language they are written in. That's because the Unix model puts a strong emphasis on the protocols for communicating between programs.

Re:“C is how the computer works” is a dangerous mindset for ... by continuational on Tuesday March 31, 2020 @04:05PM (#22741895)
Those programs communicate by serialization and deserialization, usually in bespoke, poorly documented data formats.

Unix doesn't put a strong emphasis on protocols. It just says "everything is text, except when it's not". It's not very helpful.

Re:“C is how the computer works” is a dangerous mindset for ... by effie on Tuesday March 31, 2020 @05:16PM (#22742671)
Modern unix gives you mostly low-level mechanisms, not inter-application protocols. It is better to leave it up to applications/administrators to figure out the best protocol (policy) for their use case, to make the best use of those mechanisms.

Those mechanisms aren't textual, they are byte-sequence based.

It turns out that many text-based protocols are more popular than binary/object alternatives. The penalty for textual redundancy is negligible/acceptable for many of them. Where not, Unix allows people to use unix/create new mechanisms to implement specialized protocols (rpc, protobuffers,...).

Re:“C is how the computer works” is a dangerous mindset for ... by lliamander on Tuesday March 31, 2020 @04:45PM (#22742364)
> Unix doesn't put a strong emphasis on protocols. It just says "everything is text, except when it's not". It's not very helpful.

OK, I probably misspoke by claiming it put an emphasis in protocols, but I think it's fair to say that Unix does emphasize component integration by sharing data instead of trying to integrate through a common runtime.

I do think that having everything be (mostly) text is helpful though. It's true that the data formats are often poorly specified, but that is compensated for by the fact text is a format that has a very rich set of tooling. text editors, regular expressions, parser-generators, etc. all make it possible to capture, analyze, and manipulate the text data exchanged.

Perhaps a better example of protocol-based integration would be the internet. It has it's flaws as well, but it's also enabled collective engineering projects on a vast scale.

Re:“C is how the computer works” is a dangerous mindset for ... by adev_ on Wednesday April 01, 2020 @03:07AM (#22746420)
You got it yes. And very few Software Engineer understand that unfortunately.

The reason C is so successful is named ABI.

C (and C++ to some extend) can be used to produce library that can be used from any higher level language in existence. And this is strictly required in the heterogeneous world we live in.

If you have to write a system components, long lifetime, implementing a protocol / database / format / any-low-level-staff: You do not have choice, safety or not. It is going to be C or C++, because it is the only thing reusable in most other environment.

Python has pybind11, Java has JNI, Lua operate beautifully with C/C++, Node is itself C++, go has cgo, Ruby is in C, any proper programming language can interface with C or C++.

They are the only languages allowing that, and that is why they are still alive, very well alive, even if they are unsafe.

As long as new language authors will be more obsessed about supporting new fancy feature instead of providing a well defined ABI (C compatible). The situation will not change.

Rust might be the new comer in this area that has its chance. But for the time being, it is still too young: you have to map every Rust API to a C one manually to make it exportable.

Re:“C is how the computer works” is a dangerous mindset for ... by jeffdavis on Tuesday March 31, 2020 @04:05PM (#22741892)
Lisp is an interesting point. I guess the argunent is that it's the right tool for every job?

Unix is a reasonable example of a polyglot environment, but at a high cost. Lots of serialization/deserialization through text. That has a high cost in terms of bugs, complexity, lines of code, and inefficiency.

Re:“C is how the computer works” is a dangerous mindset for ... by lliamander on Tuesday March 31, 2020 @04:36PM (#22742249)
> Lisp is an interesting point. I guess the argunent is that it's the right tool for every job?

Yup, that's more or less the argument, though the argument need not only apply to lisp.

> Unix is a reasonable example of a polyglot environment, but at a high cost.

I'd rather say that Unix is an example of how to effectively drive down the cost of a polyglot environment to a point where it is outweighed by the benefits.

Now, of course the cost is still there, but I would argue that beyond a certain scale you cannot optimize globally on a single runtime (perhaps not even with something like lisp) and so the cost of global consistency is outweighed by cost of being unable to optimize locally.

To put it more succintly, you could not build a system as complex as Unix in a single language[1]

[1] Although Ala Kay's work at VPRI suggests you can, if you choose a sufficiently expressive base language. But even that may have it's limits.

Re:“C is how the computer works” is a dangerous mindset for ... by saagarjha on Tuesday March 31, 2020 @02:00PM (#22740408)
> Rust seems to have this superpower (does dynamic dispatch a different way than C++, so can always work on unmodified structures).

This isn't really true.

Re:“C is how the computer works” is a dangerous mindset for ... by jeffdavis on Tuesday March 31, 2020 @03:52PM (#22741736)
Can you explain?
Re:“C is how the computer works” is a dangerous mindset for ... by saagarjha on Tuesday March 31, 2020 @04:04PM (#22741878)
Rust has both static (based on monomorphization, similar to a template instantiation in C++) and dynamic (based on vtables, similar to inheritance in C++) dispatch: https://doc.rust-lang.org/1.8.0/book/trait-objects.html. Both Rust and C++ are moving in the direction of encouraging static dispatch.
Re:“C is how the computer works” is a dangerous mindset for ... by steveklabnik on Tuesday March 31, 2020 @04:48PM (#22742393)
It may be similar, but it is implemented very differently, in exactly the "so can always work on unmodified structures" sense.

Trait objects are a double pointer: one to the vtable, and one to the data. C++'s dynamic dispatch uses a single pointer to a structure that has the vtable and the data. The memory layouts are very different.

Re:“C is how the computer works” is a dangerous mindset for ... by jeffdavis on Tuesday March 31, 2020 @05:53PM (#22743077)
"The memory layouts are very different."

Clarification: the memory layouts between C++ dynamic dispatch and rust dynamic dispatch are very different.

Rust imposes no requirements on the structure layout, whereas C++ adds some magic data. The magic data means it's awkward to make C++ do dynamic dispatch on a C struct pointer; but rust can do dynamic dispatch on a C struct pointer with no problem.

Re:“C is how the computer works” is a dangerous mindset for ... by munificent on Tuesday March 31, 2020 @01:00PM (#22739639)
> Use Java, use JS, use python, go, rust... whatever suits for the task.

A primary factor that determines whether a particular language is suitable for a task is its runtime performance.

> constantly trying to compare everything to C.

C has little runtime overhead and incredibly mature compilers, so it is an excellent target to use when measuring another language's runtime performance. "Close to C" is simply a synonym for "the language adds little runtime overhead".

Re:“C is how the computer works” is a dangerous mindset for ... by tux3 on Tuesday March 31, 2020 @12:41PM (#22739411)
> all that are complaining about it in whatever way possible or compare to it, will probably never be involved in a task where C excels, so why bother?

I don't think that's a fair assumption. You may be underestimating the number of developers who have a need for a systems programming language.

Re:“C is how the computer works” is a dangerous mindset for ... by stiray on Tuesday March 31, 2020 @12:48PM (#22739486)
Sure, I do. I am just hooking linux kernel calls, I will never take JS for this. Pure C. Valgrind? I have a header with #define MALLOC/FREE/REALLOC/... which returns larger buffer with guards at beginning and the end while after 25 years of C I hardly do anything more problematic that this. But seriously, would you give JS developer making kernel module? Ruby? PHP? No. So I wont compare with them and I would expect they would stop comparing to C. It is not the same task they are made for. I am sick of constant moaning about who is faster and who is better and who is cutter,...

System language? Make it. I dont care, if it will work better than C for the task, I will take it. If it is just a newage nonsense wasting resources for the sake of deallocating and taking care about buffer boundaries as it is so hard to take care and track your memory I will skip it. I dont care if I take a hammer or brick for using a nail, I will use what works best and my requirement is that I dont need 20 people to hammer in one nail for the sake of no one getting hurt due to putting its finger between hammer and nail. Someone would rather have a safety inspection. Also a fine decision as far as I care. Not my choice but I couldnt care less.

---

Anyway, kids, downvoting me to censor what you cant handle, I am over 40 years old, developing for my whole my life. I have seen hypes, new "revolutionary" ideas, repacking old technologies as new, stealing ideas (I see this lately 24/7) at least 20 new "revolutionary" languages, cpus, mainframes, clouds, any possible way of another human trying to rip you off (google, fb,...), lies, deceit, preaching, evangelism,... Do you really think I will care about it? It is just sorry truth that you will have fun of enjoying kernels written in JS on a browser, on a linux kernel that no one develops any more. Have you seen movie Idiocracy? You really should. I cant wait for it to happen. And then will I ask you if you are sorry, that 20 years back you didnt rather decide to learn instead of copy/pasting and spitting over everything you are unable to handle. (your parent should told you that, but they didnt, I am sorry)

----

saagarjha: sure, ignore the part about censoring, that is not part of debate. About everything else. You get used to it in a same manner as using floats in js. But this is my expirience. It is completely ok, to have different one. Some people are memorizing decks of cards, i consider that something difficult. They probably dont. They have learned to do it. And I am so sorry if dont feel like I need to prove it to you. Anyway, thank you for the cycript.org link, the only problem is that i cant use userspace solution, but it might come handy some day.

Re:“C is how the computer works” is a dangerous mindset for ... by saagarjha on Tuesday March 31, 2020 @01:26PM (#22739938)
I'm just going to respond to the top part of your post, as it's at least somewhat relevant rather than being a disconnected rant about the kids censoring you.

> I am just hooking linux kernel calls, I will never take JS for this. Pure C.

Why not? Hooking native code in other languages is already fairly common: http://www.cycript.org

> Valgrind? I have a header with #define MALLOC/FREE/REALLOC/... which returns larger buffer with guards at beginning and the end while after 25 years of C I hardly do anything more problematic that this.

Valgrind does significantly more checks than your solution.

> System language? Make it.

"Systems language" is a very ill-defined term, often used to gatekeep people.

> If it is just a newage nonsense wasting resources for the sake of deallocating and taking care about buffer boundaries as it is so hard to take care and track your memory I will skip it.

Keeping track of your memory is hard. If you say "no, it's easy for me", I'd like to see a non-trivial sample of your code that doesn't have memory safety issues.

Re:“C is how the computer works” is a dangerous mindset for ... by ncmncm on Tuesday March 31, 2020 @03:01PM (#22741163)
It is easy for engineers, because engineers are trained to make things correctly even when that is inconvenient.

Engineers make bridges that don't collapse (unless not maintained for decades) and planes that don't fall from the sky (unless overruled by management). By the evidence, it is not easy for people who just can't be bothered to take the time to make anything correctly.

So, there are languages for engineers to use to make things where it matters if they are right, and languages for everybody else, where apparently it doesn't. Now, all we need is for engineers not to need to call into libraries not written by engineers.

Re:“C is how the computer works” is a dangerous mindset for ... by wasted_intel on Tuesday March 31, 2020 @05:35PM (#22742881)
> it is not easy for people who just can't be bothered to take the time to make anything correctly

Laziness may make the problem more likely, but even a disciplined team working on security-critical software can make mistakes[0].

[0] https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-0777

Re:“C is how the computer works” is a dangerous mindset for ... by jeffdavis on Tuesday March 31, 2020 @01:49PM (#22740264)
"people would like to use wrong tool for the job"

That's actually a great way to learn. I do that intentionally sometimes to force myself to understand a problem better. Sometimes it even works[1]!

I'm half serious here. Clearly when something is important and needs to be timely, choosing the right tool is important. But my comment is not sarcastic, either: choosing the wrong tool really is a great way to understand your tools and the problem more deeply.

[1] https://github.com/jeff-davis/postgres-extension.rs

Re:“C is how the computer works” is a dangerous mindset for ... by hermanradtke on Tuesday March 31, 2020 @05:12PM (#22742634)
C is the lingua franca of the programming world. Of course people are going to compare xyz language to C.