3 ms·
For me it was a big case of Not Invented Here syndrome that caused me to make my own compilers and languages. It is a great way to learn deep stuff about how la
by bartwe 15y ago
For me it was a big case of Not Invented Here syndrome that caused me to make my own compilers and languages. It is a great way to learn deep stuff about how languages work, and helps me debug issues that others can't fix.
- palish 15y agoIssues such as?
- veyron 15y agofor example: C has a bunch of undefined expressions which give you different results on different compilers (as an example, j = i++ + ++i;) Now, this makes perfect sense if you understand the concept of sequence points, but you wouldnt see that explanation in most books.
- palish 15y agohmm... j = i++ + ++i; .... To me, it seems like that would be evaluated by operator precedence... ++ has a higher precedence than + So let i=1. The expression then becomes: j = i++ + ++i; j = {1}++ + ++{1}; j = 1 + 2; OR, j = 1 + 3; Aha. And that's the undefined behavior. Ew. That seems like the type of problem which shouldn't have to be debugged, because the code shouldn't have been written like that to begin with. Heck, it seems like the compiler shouldn't even allow that code to compile in the first place... But I guess there are technical problems with disallowing that? (Not the least of which is, it would break existing code.)
- veyron 15y agoThe issue comes from some vagueness in the wording from the C standard. The expression is valid from a literal interpretation of the rules, but to eliminate it would require a much more convoluted set of rules. Remember that C historically was a single-pass compiler ... And if you want to get even funkier, try this in other languages (python yields 2, bash yields 4) $ python -V Python 2.6.1 $ python -c 'x=1;y=x++ + ++x; print y' 2 $ x=1; echo $((x++ + ++x)) 4
- kingkilr 15y agoPython is not doing what you expect here, it sees that as: y = x + (+(+(+(+x))))
- MostAwesomeDude 15y agoYou appear to not understand how Python works. Python has no increment operators; your statement is equivalent to "x + ++++x" or "x + x", using the unary + operator.
- veyron 15y agoFor those that didn't understand, my point with the python example was to emphasize that the same expression (visually) can have different meanings in different languages, and that the parse rules can be different. I am aware that python doesn't parse it in the way that the expression appears to a C programmer :) Concerning python's lack of pre and post increment, the decision was made primarily because there are a lot of confusing situations, such as the aforementioned, with the increment and decrement operators. However, the decision to allow x++x to be valid, and parsed as x + (+ x) = x + x, is itself terribly confusing and germane to the original discussion
- mdaniel 15y agoAs someone who has to endure the results of NIH, I want to say that such thinking is a poison to the industry. I wish that, if someone is overcome by the vapors of the NIH disease, such a person would confine their reinvention of the wheel to their personal time and not introduce such silliness to the workplace. Of course, I wish for lots of things.
- nitrogen 15y agoI got the impression from bartwe's post that the NIH symptoms were confined to personal/learning time.