News for hackers. Stuff that matters.
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @02:09AM (#29711289)
C is a 3-rd level of abstraction language. Currently, there is no 4-th level of abstraction, so C is a high-level language by definition of «level of abstraction».

Language levels of abstraction:

1. Machine code

2. Assembler

3. A high-level language

C does allow low level things, e.g. access of machine registers or embedding of assembler or machine code, but it is also capable of quite high level of abstraction.

Some of 3-rd level languages allows higher level of abstraction, or hide low level abstractions, e.g. memory management, stack, byte order, bits per number, etc., hover none of them improves programmer productivity by an order of magnitude.

Re:C Is Not a Low-level Language (2018) by junon on Tuesday December 28, 2021 @08:02AM (#29713362)
Err... what? Did you make these terms up yourself, or are these established in some literature already? Because they make no sense.

C isn't converted into assembler language unless you ask the compiler to. For example, LLVM lowers IR AST structures into target specific machine code. Assembler is never involved.

ASM is just a human readable representation of machine code for a particular ISA. So in your mental model, C and ASM exist at the same level.

Further, Java bytecode would exist above the the machine code level (again, alongside C then, since the VM is compiled to machine code) and Java on top of that.

It just doesn't make any sense to define languages like this. I don't see any benefit, and I don't even see it as being correct.

Re:C Is Not a Low-level Language (2018) by rezaprima on Tuesday December 28, 2021 @08:57AM (#29713790)
perhaps he/she meant 3rd generation language. https://en.wikipedia.org/wiki/Third-generation_programming_l...
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @10:25AM (#29714588)
3 generation of languages were powered by increased level of abstraction, which was enabled by increased capabilities of hardware. 4th generation can (will?) be powered by AI.
Re:C Is Not a Low-level Language (2018) by junon on Tuesday December 28, 2021 @09:01AM (#29713821)
Just because it's on Wikipedia doesn't mean it's a real thing. The only source for that page is some bizarro, circa-1998 website about "computer jargon". These are not academic terms that I've personally ever heard of. Happy to be wrong, but I'm not going to pretend they have any utility or legs.
Re:C Is Not a Low-level Language (2018) by uxp100 on Tuesday December 28, 2021 @09:12AM (#29713930)
3gl 4gl 5gl were common terms 30 years ago or so. More industry and advertising terms than academic. And 5gl was more like a Japanese government grant program than any particular set of language features IIRC.
Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @09:25AM (#29714052)
My memory of the whole "nGL" language thing was that it was more a marketing term than anything you would find in an academic paper. It was particularly common in the IBM world, for example in books[1] and advertisements[2]

[1] https://www.oldcomputerbooks.com/pages/books/R504/james-mart...

[2] I can't find a good example, but I remember seeing ads for "4GL" tools in Dr Dobbs regularly in the mid-90s.

Re:C Is Not a Low-level Language (2018) by int_19h on Wednesday December 29, 2021 @03:13AM (#29722932)
On PC, I remember platforms such as dBase were often referred to as 4GL. In retrospect, it feels like was a short way to say "very high-level domain-specific language for databases".
Re:C Is Not a Low-level Language (2018) by resonious on Tuesday December 28, 2021 @10:27AM (#29714605)
The "high-level lang, assembly, machine code" model is pretty much how it's taught in schools and random internet tutorials. As usual, the real world is a little more nuanced.
Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @09:16AM (#29713975)
> C isn't converted into assembler language unless you ask the compiler to. For example, LLVM lowers IR AST structures into target specific machine code. Assembler is never involved

That depends on the compiler. GCC, for instance, most certainly emits assembler code as part of its standard compilation process.

Re:C Is Not a Low-level Language (2018) by vlovich123 on Tuesday December 28, 2021 @09:57AM (#29714339)
GCC to my knowledge has long-switched to IR as well. It’s called GIMPLE [1]. Can you please substantiate your claim?

[1]. https://gcc.gnu.org/wiki/GIMPLE

Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @10:51AM (#29714829)
Well, there this[1] page that describes the GCC architecture:

"The SSA form is also used for optimizations. GCC performs more than 20 different optimizations on SSA trees. After the SSA optimization pass, the tree is converted back to the GIMPLE form which is then used to generate a register-transfer language (RTL) form of a tree. RTL is a hardware-based representation that corresponds to an abstract target architecture with an infinite number of registers. An RTL optimization pass optimizes the tree in the RTL form. *Finally, a GCC back-end generates the assembly code for the target architecture using the RTL representation.* Examples of back-ends are x86 back end, mips back end, etc."

Then, there's the official GCC documentation[2]:

"Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file."

You can also just run GCC -- either with --verbose or --save-temps -- and observe what the compiler toolchain is doing.

[1] https://en.m.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU...

[2] https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Overall-Option...

Re:C Is Not a Low-level Language (2018) by vlovich123 on Tuesday December 28, 2021 @02:19PM (#29716921)
Not really sure what you’re arguing for. All optimization passes operate on GIMPLE.

> SSA GIMPLE is low level GIMPLE rewritten in SSA form.

I’m by no means a compiler internals expert, but to my knowledge there’s no translation from RTL to assembly. The compiler is directly emitting the machine code directly without first emitting assembler. You have to ask the compiler to serialize to assembly explicitly.

> several assembler input files, or into one assembler input file; then each assembler input file produces an object file,

That doesn’t sound right. Seems more like an abstract description. You can’t dump assembly out of an object file either. You have to do a conversion from an intermediary form to get back out a form of the assembly.

I think at this point it’s splitting hairs but assembly is not used as an intermediary at any point, even for generating machine code.

Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @03:52PM (#29718010)
> Not really sure what you’re arguing for. All optimization passes operate on GIMPLE.

You asked me for a citation. I provided two, as well as a means by which you could see for yourself that what I am saying is correct.

Believe what you want, but all of the GCC documentation, as well as the output of the compiler if you run with --verbose or --save-temps supports what I have described of GCC's operation.

The compiler internals manual[1] also describes the backend machine descriptions, and how they are used in detail:

"There are three main conversions that happen in the compiler:

1. The front end reads the source code and builds a parse tree.

2. The parse tree is used to generate an RTL insn list based on named instruction patterns.

3. The insn list is matched against the RTL templates to produce assembler code."

[1] - https://gcc.gnu.org/onlinedocs/gccint/Overview.html

Re:C Is Not a Low-level Language (2018) by Ginden on Tuesday December 28, 2021 @04:10AM (#29711883)
Such definition is just useless and therefore should be abandoned.

> hover none of them improves programmer productivity by an order of magnitude.

I disagree. I can write efficient SQL statement in 2 minutes, but implementing efficient multiple "table" join with spill to disk took me much longer than 20 minutes.

Re:C Is Not a Low-level Language (2018) by delusional on Tuesday December 28, 2021 @07:53AM (#29713300)
Agreed. I can't really believe I am reading this discussion. Languages are just user interfaces. It's OBVIOUS that there's a difference between the granularity of the Java UI and the C UI. It's also OBVIOUS that such a difference would greatly impact the speed of use. I could write a garbage collector in C, in Java it's already there. The whole point is discussing those differences, so anyone saying they are the same has completely missed the point of the discussion.

It's like saying Windows 11 and OS/2 are the same because they are both Operating Systems.

Re:C Is Not a Low-level Language (2018) by coliveira on Tuesday December 28, 2021 @09:31AM (#29714123)
What you're missing is the level of comparison. Everything is different from everything else if you're looking only at differences. But if you want to classify concepts, you need to determine what are the similarities. So, yes, if you're talking about objects in the category of operating systems, W11 and OS/2 are in the same category. If you're looking at languages that offer high level constructs, C and Java are at the same level. Languages that offer only direct machine instructions (assembly) are at an inferior level.
Re:C Is Not a Low-level Language (2018) by loup-vaillant on Tuesday December 28, 2021 @11:20AM (#29715084)
SQL is a special purpose language. Special purpose languages can be amazing (and SQL certainly is), but here we’re comparing general purpose languages.

In this context, the question is more, are Lisp or Haskell, or Python 10 times as productive as C? I used to think so, but now I seriously doubt it.

I mean, the reason I’m so much faster at writing small Python programs than I am at writing equivalent C programs, is because Python’s standard library is so damn huge. This is not a case of the language being more productive, this is a case of the work already being done.

Re:C Is Not a Low-level Language (2018) by pkolaczk on Tuesday December 28, 2021 @11:32AM (#29715210)
If someone gave you a library of functions for doing table joins in C, it wouldn't take you much longer than those 2 minutes as well.
Re:C Is Not a Low-level Language (2018) by jug on Tuesday December 28, 2021 @07:43AM (#29713222)
I'd argue that the class of languages running within a virtual machine like Java (JVM) or .NET (CLR) ought to be placed in a higher level of abstraction. These are so detached from the physical reality that they become cross-platform, which in itself is also the goal.
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @09:15AM (#29713960)
C is the most cross-platform language today, because almost every platform supports C. JVM is written in C, for example, for portability.
Re:C Is Not a Low-level Language (2018) by Sindisil on Tuesday December 28, 2021 @10:20AM (#29714543)
The most prevalent JVM is written mostly in C++, not C.

Your portability point mostly stands, though.

Re:C Is Not a Low-level Language (2018) by saagarjha on Tuesday December 28, 2021 @05:57AM (#29712443)
Respectfully: are these levels just something you created for this comment, or are they actually something you can back up with literature that agrees that they are the right levels or that they even exist at all?
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @10:14AM (#29714491)
These levels are learned by software engineers on introduction to compilers.

«A Compiler is a software that typically takes a high level language (Like C++ and Java) code as input and converts the input to a lower level language at once.»

«Assembler A translator from assembly language programs to machine language programs.

Compiler A translator from “high-level” language programs into programs in a lower-level language.

Transpiler A translator from high-level language programs into programs in a different high-level language.»

«The compiler is software that converts a program written in a high-level language (Source Language) to low-level language (Object/Target/Machine Language).»

Re:C Is Not a Low-level Language (2018) by bee_rider on Tuesday December 28, 2021 @03:09AM (#29711578)
That, in the conventional classification, C is considered a high level language, is definitely what I learned in some languages class. This seems like an odd result given that it is probably the least abstract language that the vast majority of programmers might ever encounter, outside the exercise or two on assembly that they might see in an architectures class. Sort of how, as far as I know, most (all?) PIC and AVR microcontrollers would be considered "very large scale integration" chips.

This the best possible outcome, though -- since they used up these kind of "biggest classification that doesn't sound totally silly" labels in the 70's and 80's or whatever, we don't have to worry about classifying languages anymore, which was not really all that productive to do anyway.

Although I do wonder what level Verilog should be considered.

Re:C Is Not a Low-level Language (2018) by saberience on Tuesday December 28, 2021 @02:52AM (#29711493)
I would define fourth level languages by what they allow you to do, or what foot-guns they provide you with.

For example, surely languages like Typescript are "level 4" as you cannot manipulate memory directly but only use the languages higher level type structures.

Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @03:07AM (#29711571)
On fourth level of abstraction, no procedures or functions are used. Copilot is at 4th level.
Re:C Is Not a Low-level Language (2018) by hyperman1 on Tuesday December 28, 2021 @03:18AM (#29711614)
The 1980's want their marketing back.

https://en.wikipedia.org/wiki/Fourth-generation_programming_...

They considered things like excel 4GL: You program some formulas and excel magically finds out what the necesarry steps are to do the computation.

A lot of vendors created graphical programming languages and declared them 4GL. The term mostly died because nobody could stop laughing.

Re:C Is Not a Low-level Language (2018) by galangalalgol on Tuesday December 28, 2021 @04:10AM (#29711881)
The term died, the dream festered on. It got rebranded as model driven development andany in the embedded world bought into it in the late 90s, some have only ditched it in the last year or two, while plenty more have followed a second rebranding and keep drawing... There are some good graphical languages, lego mind storm, code spells, gnu radio companion, simulink, and maybe, sometimes, labview. Those languages aren't object oriented, they represent data flow. I suspect that makes a difference. But mostly they are for quick prototyping or small designs. And that makes an even bigger one. Diagrams don't scale well.
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @10:52AM (#29714848)
Level of abstraction ≠ Generation of languages.

The first 3 generation of languages were powered by higher levels of abstraction, which were possible because of better machines.

However, further increase in level of abstraction did not make developers an order of magnitude more productive, except for niche areas. Switching to a better development process (Scrum) can achieve order of magnitude improvement in developer performance, while switching of programming language cannot.

Anybody can claim that their product is a next gen revolutionary market shaking breakthrough. It's the self-promotion, not a science.

Re:C Is Not a Low-level Language (2018) by usrbinbash on Tuesday December 28, 2021 @04:16AM (#29711911)
Erm...Copilot still writes procedures and data types, most of which I have to describe one by one.

And I still have to review all of them.

How is that "4th level abstraction" whatever the current usage of the term?

Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @05:52AM (#29712408)
3rd level languages are compiled into 2nd level languages (assembler, or byte code, or intermediate representation), then into machine code.

Transpilers are compiling from one 3rd level language into another 3rd level language.

Code generators or macros are receiving data and producing code in a 3rd level language.

4th level language receives plain text explanation of a goal and produces code in a 3rd level language. AI based tool is the only tool which is capable to do that, because such process requires understanding of the goal, not a mechanical transformation of input into output. It's possible to implement such AI in Lisp, Prolog, or using ML. Copilot is an example of such AI.

Re:C Is Not a Low-level Language (2018) by usrbinbash on Tuesday December 28, 2021 @06:16AM (#29712592)
>4th level language receives plain text explanation of a goal and produces code in a 3rd level language.

Such an explanation would read like this:

    I require some glue code so the system our company uses to pass messages between our services, can talk to the system of the company we talked to 2 days ago. Also, there should be a web interface or something to monitor it.
Not like this:

    A function that queries the user from the database by its surname
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @10:31AM (#29714640)
Such explanation can be like this:

  apt-get install foo bar baz
Just few words, but they can generate very complex ready to run systems.

Unfortunately, this is not a general-purpose language, but apt + shell is.

Re:C Is Not a Low-level Language (2018) by usrbinbash on Tuesday December 28, 2021 @11:52AM (#29715432)
How is this the "explanation of a goal"?

I issue an imperative command to apt-get, and it tries to execute it.

It has no knowledge of why I want foo bar and baz installed, nor can it decide if these 3 programs make sense for what I am trying to do, or if there is a better way to do it (maybe there is a package "bazinga", that can replace the foo-bar-baz stack?).

A goal-aware package manager would look like this:

   super-apt "i need the system ready to function as a webserver, with a high availability database and backup capabilities"
Re:C Is Not a Low-level Language (2018) by drran on Wednesday December 29, 2021 @05:23AM (#29723531)
> A goal-aware package manager would look like this:

A typical package manager is already goal-aware, like `make`. It's input DSL is far from English, but it's not hard to translate your English sentence into «apache postgress rsync» by matching text to package descriptions.

Package manager requires a solver for dependencies, constraints, and conflicts, which is far from trivial. For example, Fedora(RedHat) switched from in-house solver for yum/dnf to zypper SAT solver (libzypp) developed by SuSE/Ximian/Novell.

Unfortunately, package managers are DSL, not a general purpose language.

Re:C Is Not a Low-level Language (2018) by rndm_access on Tuesday December 28, 2021 @02:10AM (#29711296)
Which layer is Forth? xD
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @03:04AM (#29711558)
WTF is layer?

If you are asking what level of abstraction is used by Forth, then the answer is: 2nd. It directly exposes stack, memory, and machine code and provides a thin wrapper on top of that. Developers can build higher levels of abstraction then, of course. It's possible to do an object-oriented programming in machine code, because compiler can.

The trickier question is: What level is Lisp? Is it assembler for Lisp machine (because of opcodes like car, cdr, etc.)? Or, maybe, it is a 4GL because of it advanced meta-programming possibilities?

Re:C Is Not a Low-level Language (2018) by von_lohengramm on Tuesday December 28, 2021 @03:19AM (#29711616)
That does not describe all Forths. A Forth running on a Forth CPU would certainly be a 2nd level, but depending on how the Forth is implemented and designed, it could easily be seen as a 3rd level. Arguably, Forth is (can be) more abstract than C and almost a quasi-FP.
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @05:44AM (#29712356)
It's possible to implement high-level abstraction in machine code, or compile a high-level language into low level machine code, however it's not possible to hide low-level, machine dependent details in a low level language. It's not possible to hide machine opcodes in machine code, or CPU registers in assembler, or stack in Forth, so a developer must learn these things and deal with them, which makes the development process slower.

So, it's expected to see an order of magnitude improvement in development speed, on average, when jumping from machine code to asm, or from asm to a 3rd level language. Forth doesn't improve speed of development by an order of magnitude comparing to asm, because of the steep learning curve and low level stack management. I tried to learn Forth multiple times, but still cannot program in Forth freely, which makes it unique among 20+ other programming languages I know.

Re:C Is Not a Low-level Language (2018) by lebuffon on Tuesday December 28, 2021 @10:43AM (#29714749)
IMHO Forth has a longer learning curve than other languages and requires a significant mental model shift if you are use to conventional languages. It does not suit everyone. It seems more like learning a new human language with a large number of words.

Chuck Moore created Forth to improves his productivity versus conventional tools and there is some anecdotal evidence that it worked for him and those that worked with him, particularly where direct hardware control on new hardware could be interrogated and validated via the interpreter rather than an Edit/Assemble/Link/Test loop.

Re:C Is Not a Low-level Language (2018) by endymi0n on Tuesday December 28, 2021 @02:56AM (#29711511)
Which layer is an embedded Lua script controlling execution of a Java program running on the JVM within Rosetta2 and then getting translated into ARM microcode within the M1 CPU?
Re:C Is Not a Low-level Language (2018) by astrange on Tuesday December 28, 2021 @01:59PM (#29716731)
M1 doesn’t have microcode; that’s an AMD/Intel implementation detail.
Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @09:35AM (#29714150)
I don't know about layer, but according to this book[1], it is a fourth-generation language. I've never associated it with RPG and FoxPro, but I guess you learn something new every day.

[1] - https://www.discoverbooks.com/Forth-The-Fourth-Generation-La...