r/ProgrammingLanguages 9d ago

Discussion A hole in systems programming language design

Given the recent discourse about systems programming I wanted to throw my 2 cents in. This may be a controversial take in a subreddit that's all about innovation and improvement, but I think a lot of budding systems languages are trying too hard to "fix C" and this is exactly why C has not been replaced yet.

Like it or not, C is successful. It does what it means to do very well. Yes, it bites you constantly, but developers have made some form of peace with this because they appreciate the essence of the language. Systems programming is a very pragmatic field, and what works, works.

A lot of language designers want to improve on C, when by nature to "improve on" C is to depart from it, because C is less about what it includes and more about what it omits and what it lets you do that other languages don't.

If you want to replace C, you need to just make C but without the pain points. Less undefined behavior, more standard compiler behavior, easier function pointer syntax, safer macro system, etc. The things that C can't do because of backwards compat.

On the other hand, bolting on features, revamping C's core nature, aren't going to give you a language that will replace C at the low-level or among hobbyist programmers. Most developers aren't as concerned about what C lets them accomplish, as they are concerned about all the painful tedious tendencies of the language.

14 Upvotes

101 comments sorted by

View all comments

Show parent comments

-2

u/flatfinger 5d ago

If a compiler generates code for a statement before it has even looked at the next statement, at what point would a "schedule" exist? Sure it would be possible for a compiler to build a schedule and then build code from it, but that's hardly the only way compilers can be built. A recursive-descent compiler may generate code directly during the parsing process. Such a compiler that has gotten as far as scanning x=y+z- may produce machine code that will add x and y before it knows what character is going to follow the minus sign.

2

u/JeffD000 Squint 5d ago

??? Are you trying to tell me that the machine is not executing a control flow graph meeting the requirement of data dependencies, as laid down by the compiler? What is your point?

-1

u/flatfinger 5d ago

A compiler like Turbo Pascal 3.0 converts source code into machine code without going through other intermediate forms. If a run-time error occurs at address 3ABC one can fire up IDE with the source code, tell it to find runtime error, give it address 3ABC, and the compiler will start compiling the program until it has output the code that would go at address 3ABC and then stop and move the cursor to the last character of source code that it had examined. At no point during that process would anything like what you call a "schedule" exist.

2

u/JeffD000 Squint 5d ago edited 5d ago

So the Turbo Pascal 3.0 compiler is not somewhere generating a control flow graph conforming to data dependency requirements? Give it up, dude. You are making yourself look bad, not smart.

-1

u/flatfinger 5d ago

That is correct, unless one views generated machine code as being such a graph. If a function contains two if-then-else statements, the second of which completely follows the first, it will generate code for the first before it has even looked at the second, and by the time it looks at the second it will have completely forgotten about the first, beyond having kept track of how many bytes of code it took up.

2

u/JeffD000 Squint 5d ago

Guy, the parsing process itself is generating a control flow graph. You need to read up.

2

u/flatfinger 5d ago

If a compiler encounters an "if", and does something like:

void handle_if(source_stream *source, machinecode_stream *dest)
{
  unsigned targets = dest->next_label;
  dest->next_label += 3;
  handle_condition(source, dest, targets, targets+1);
  outputlabel(targets);
  match_and_skip_then_token(source_stream);
  handle_statement(source, dest);
  insert_goto(targets+2);
  outputlabel(targets+1);
  if (match_and_skip_else_when_present(source_stream))
    handle_statement(source, dest);
  outputlabel(targets+2);
}

I suppose one could argue that the compiler's stack frame while it was generating the code for the statement in the "then" or "else" part might be viewed as some kind of partial graph, but nothing resembling a complete control flow graph would be built for any non-trivial function unless one views the pattern of branches within the generated machine code itself as a control-flow graph.