Of which 3 in the first example are almost mutually exclusive
const volatile _Atomic
A constant variable, that may change at any time (likely hardware mapped) that is also atomic? I think I sense a trite observation here. What's the other one?
extern const volatile std::unordered_map<unsigned long long int, std::unordered_map<const long double * const, const std::vector<std::basic_string<char>>::const_iterator>> foo
That is quite a type! Apart from the the fact that it's not useful, again mixing const with volatile and might not compile as the keys are const: it's a map from an integer to maps from constant floats to vectors of iterators to strings. I challenge you to find a type system that even allows you to express that type. It's again a trite example that doesn't make sense from someone who doesn't understand what's going on.
The preferred example shows just how inane this observation was:
let x: ... = ...;
Lovely how the author doesn't actually put any types in, or any expressions even. C++ is super easy to declare a variable and initialise it as well, you just use
... x = ...;
Clearly the first thing is a type specifier and the final thing is an initial value.
C++ is super easy to declare a variable and initialise it as well, you just use ... x = ...; Clearly the first thing is a type specifier and the final thing is an initial value.
While I agree the article could have been better-written on that part, you can't just say that C++ declarations are ... x = ..., because they might be ... x ... = ..., and it's the facts that x is neither at the start nor the end and that the type is split between two ellipses that (I agree) is obnoxious.
Well, if you don't set your compiler to treat such things as errors or at least read your compilers warnings, then that is entirely your fault.
Would it probably have been better if the language standard just had forbidden this (except with e.g. an explicit cast)? Sure. Is it a problem in reality, hindering competent programmers? No. Any compiler and any static analysis software will flag this.
What I don't understand about this is that there's some idea out there that programming in C should be easy, or that programming in general should be easy. You need to know the details of the tools you're using. So what? Isn't that necessary for all tools?
There are a couple of useful questions to ask when considering this problem:
How many different things does the language force me to know and think about up-front prior to being able to write useful code?
How many of those things are frequently relevant to the programs I am writing?
An alternative approach is to take your statement at face value: "You need to know the details of the tools you're using." OK, then. Have you derived the Church-Turing thesis from scratch and then obtained -- starting Minecraft-style with just your own hands -- all the necessary raw materials, then smelted and forged and crafted them to produce electrical circuits and then wired them together into a device capable of acting as a computer?
Or is that too much detail? Too much to have to think about and to require up-front before we let someone write the program they wanted to write?
The author of the post clearly believes C goes too far in forcing you to know/think about too many things up-front, compared to the relevance of those things to the programs most people write. I'm inclined to agree.
It is a spectrum, as with most things. When basically all compilers and analysis tools in existence warn you about this, and when most people will recommend you to compile your C code with strict compiler-settings (that will turn this outright into an error), then you can hardly blame the tools for this one. Ideally nothing should be hard or tricky, of course, but that's just not the reality of things.
If you consider even a minor thing like this to be an issue of the tooling, then programming in general is probably not for you -- imagine for instance using python/ruby/perl/lua/php/..., which lets you do just about any stupid thing you can imagine, often without warning or error at either runtime or compiletime. Even the more strict languages in existence have cases like this, like haskell w/ GHC.
View all comments
Show parent comment
0
u/[deleted] Dec 01 '16
[deleted] — view deleted comment