Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
Answer: they took something that /should/ be as simple as basic pointer math and made it 1000x more complicated than that, with all kinds of type information checking and callbacks etc etc...
endor50926dReferring to the original C++: at the end of the day, it's just math. Some silly math trickery, but math nontheless.
We don't really think of it that way because of words and names and abstractions (such as language), but that doesn't change its fundamental nature.
And if math doesn't work in the world of programming, then what does? :)
Pickman6636dThe question is not why it works.
The question is "why it is allowed"?
What do you gain to have that in a language?
Root519156d@Pickman The question of "why is it allowed?" infers that there should be a list of disallowed yet completely functional things. Why arbitrarily restrict the developer? Who curates this list? Are they more knowledgeable and skilled than I? Says who? Do their arbitrary rules even make sense for my code and architecture? The compiler should never think it knows better than the programmer, and should never limit their freedom to write perfectly valid (or even questionable) code.
To blatantly simplify your question, you are asking for compilers to censor code. Fuck censorship of all kinds, and everyone who insists on it.
Pickman6636d@Root but c++ does not make everything legal. That's Brainfuck.
In reality the compiler does indeed know better.
You're mistaking syntactical flexibility for expressiveness of a language.
If in c++ you couldn't write 5[arr] you would not lose anything but the chance to write confusing code.
The compiler could easily generate the same code from 5[arr] and arr and you would never notice. At this point why not allow 5[arr]1 to be interpreted as arr+1? I'm sure that would spare me some time. If you want your code to be readable you have to make some sacrifices like writing that plus or putting the pointer outside of the brackets like everyone expects you to. Mind you, nothing wrong with unreadable code from a functional point of view. But writing it like that is being a bit antisocial. Specifically in this case it is to randomly speak like Yoda.
(Please don't do this.)
You just answered your question "it's just pointer math"
watzon49106d@root while I agree that you should be allowed to do anything, the compiler should also at least warn you if you try to do something stupid. That or there should be checks in place that make you jump through hoops to do stupid things, because where the majority of programmers are concerned the people that designed the compiler generally do know best and that warning may just say you from a major headache and hours of trying to track down a stupid bug.
Kasonnara765d@root It has already been said, but I strongly disagree with a language that allow you to make anything because it can.
You make code for a result result so yes, who care how it process internally? But to ensure it work well, to improve it, or do any modification: you HAVE to read the code and more over understand it. Tricks are sometimes cool and handy, but in most case I like if there is a single and clear way to do something. If by reading the global structure of a code you can know way it should do because everyone make it the same way you win everything. Also learning the language became simpler and thus cause less error.
However if you have to read every single character while predicting in your mind all the edge cases to get an overview because someone (or yourself) use lots of weird tricks, you will only waste your time and on top of that probably miss bugs.
Censoring what you can do is ad, but restricting how you can write it in order you ensure readability is not.
Pickman6635d@FrodoSwaggins I totally agree. Removing its legality does not however diminish the expressiveness of the language.
Considering that the de facto standard is different allowing this expose you to the temptation of writing code that is hard to read for a beginner.
Of course c++ is rather safe in that regard.
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job