Products > Programming

Forget about python! Next hype will be Zig.

(1/4) > >>

See for yourself:

"No preprocessor, no macros."

Why is that an advantage  ?
You could write C without any preprocessing but I can't see why you'd do that. It's pretty useful.


--- Quote from: artag on March 12, 2023, 02:25:35 pm ---"No preprocessor, no macros."
Why is that an advantage  ?
You could write C without any preprocessing but I can't see why you'd do that. It's pretty useful.

--- End quote ---

well, in C people abuses so much of cpp and fill so many kind of crap into #define' that it usually ends makeing the ICE confused, the code not passing any QA, and debugging sessions a bloody hell ...

... and I was so tired that "#define" (and the whole cpp-stuff) was the first thing I removed in my-c, at the cost of making "my-c" like a "schoolmarm" who properly educates my colleagues to avoid spending my time cleaning up their code  :D

You can still use #define in my-c but only to define the size of an array, and if you use it then your code is not classified as level{1..4}(1) but rather as level{5} (C89/C99 legacy).

--- Code: ---#define macro(a,b,c) .....
#define dbg_printf printf
#define foreach ...

--- End code ---

--- Code: ---#define my_array_size 1024
uint8_t my_array[my_array_size];

--- End code ---
accepted, but the code is forced as level{5} (you cannot use advance my-c features, only C89 legacy ones)

So, array size by #define is accepted, other uses are banned, alias by different word defined, macros with parameters are recognized but the front end passes them to an "insult-engine" back-end I have implemented into the compiler (built-in, you cannot disable it by any flag) to better promote the cessation and cessation of bad coding attitude.

I don't find that to be a good argument, but OK, it's your view.

For your one 'OK' usage, why would you not use const ?

If people 'abuse' cpp, it's because they want to do something otherwise difficult. If you take away that facility they will write worse code, find a worse way to do it, or use a less restrictive language. Of course, people will also abuse it. That's what coding standards are for.

Python is a great example of how this backfires. Forcing a one-size-fits-all layout just makes it impossible to use layout as an aid to understanding. Poor codewriters still write hard-to-read code in python.

One thing I like to use the preprocessor for is to create tables of values that are all derived from some common input. Alternatives would be runtime initialisation (causing slow startup - like many PC programs) or an external code-generator to produce them (so now you've got an infinite variety of preprocessors, according to taste).

You could argue that the comptime features can do that function. And they may be attractive. But, requiring emulation of the target processor, they seem a very expensive way of providing a more capable (and, therefore, abusable) compile-time-processing feature. One could use them to perform exactly the operations described as unpermitted in the preprocessor.

Zig existed for a long time, and I don't see it becoming popular. They don't even have for loops and religiously argue that they are not necessary.

And it provides no advantages on top of C. They just removed a bunch of stuff they did not like and shuffled the syntax a bit.


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod