I++ vs i+=1
-
No, no, no, you do it on a code review, as a warning to the rest of your team.
“Everyone, you know your colleague, Joe? Joe liked to do things like
i+++++i
. Joe isn't with us any more. Don't be like Joe.”
-
That was my exact reaction on first exposure to
cout << "Hello world!"
C++ was the first language I learned, so I had no exposure to the bitshift operations before seeing this. I've still never used
>>
and<<
for anything except CLI redirect and C++ cout
-
If you think about it, you actually are shifting bits in and out of the stream.
-
-
You know i am beginning to think that no one is actually reading all of my posts... They're all just getting half way through and turning into a giant squid of anger...
I do code reviews! The reason i enforce style checks automatically is because i want the code reviews to be about the algorithm and not about the code style!
-
The reason i enforce style checks automatically is because i want the code reviews to be about the algorithm and not about the code style!
But you can't catch people abusing innocent language features with a linter. You forbid
i++
, someone's gonna overload+=
to play a .mp3 of a cat in heat. Then you'll forbid operator overloading, and someone's gonna make a Duff's device. Then you'll forbidswitch
, thenfor
, and you'll be left with no language.The language feature is not your problem. People abusing said feature is your problem.
-
Yeah, and I'm putting you in the clear on the
i++
thing because most of my usecases probably don't apply to javascript anyway. Don't doarray[i++] = item
, doarray.append(item)
. Don't dofor(i = 0 ; i < 10 ; i++)
use a proper iterator. Etc.
-
And besides, you can't trust ++ in js, because you don't know if your variable's even a number in the first place. It's probably a string, or been turned into a frog or something.
-
you don't know if your variable's even a number in the first place. It's probably a string
Oh, no, it was a string. Beginning with a
0
. Which just got eaten.Well, either that or it added
1
to the last digit. In octal.
-
Or it added the letter
l
instead of a1
, “they're basically the same thing right?”
-
-
-
There was a long recent thread about sequence point on a linkedin embedded C programming group and how y = x++ - x++ is undefined behavior in C etc
-
In the second example, you have:var q = ((3+1) + 4) * (4 - 1) = 24and then i gets set to 5 after being substituted the second time
For C++.... MAYBE you have that....More likely undefined behavior for multiple accesses with modification without a proper sequence point in between....
-
There was a long recent thread about sequence point on a linkedin embedded C programming group and how y = x++ - x++ is undefined behavior in C etc
Hanzo'd
-
Man, ain't nobody got time for that shit around here
I had to fight to get my first few bits of work at this job reviewed before checking them in. Some people just want to watch the repository burn
-
I had to fight to get my first few bits of work at this job reviewed before checking them in. Some people just want to watch the repository burn
True; code reviews is something I wish we had where I work. But that's the problem with working for small companies; they just don't have the manpower to do that sort of thing properly.
-
I suppose a lot depends on the size of your team, too. We're pretty small. I try to keep an eye on certain people's check ins. But I'm not sure my customer would be willing to pay us to do reviews on everything.
-
Mikael, I would like to request that you use triple backticks (on a newline, surrounded by newlines) to delimit your code samples, rather than <code> tags, as otherwise discourse adds a bunch of spurious <br> tags that are impossible for me to get rid of:
versus
Lfunc_begin0: .loc 1 4 0 ## test.c:4:0 .cfi_startproc ## BB#0: pushq %rbp Ltmp2: .cfi_def_cfa_offset 16 Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp
-
I was referring to BenL's inevitable follow-up post about how Go does it correctly (for some value of "correctly"). Except now it's already done correctly.
-
True; code reviews is something I wish we had where I work. But that's the problem with working for small companies; they just don't have the manpower to do that sort of thing properly.
Unless you only have one developer (and thus code reviews would be pointless), you save labor via code reviews.
-
Except now it's already done correctly.
It all depends on what you mean by “correctly”. The sanest version involves pretending it's all done on bignums, as that makes integers have semantics that are very close to that of the mathematical integers, but I can understand why people might not like that (it's got non-trivial overhead, both in complexity and time).
-
The reason i enforce style checks automatically is because i want the code reviews to be about the algorithm and not about the code style!
Gee, I bet your code review meetings* are shorter because of this...aren't they? ;)
That can't be a bad thing.
I mean it's not like petty disagreement over relatively minor points of coding ever gets out of hand and results in repetitious back and back over the same territory with one side not listening to the other... (322 posts and counting as I write this.)
-
Gee, I bet your code review meetings* are shorter because of this...aren't they?
they actually are!
that's because every time we get sidetracked on style i point out that developer X's code passed the style checkpoint and if the style is wrong then we need to have another meeting to discuss the stylechecker and update it if necessary.
it keeps things moving and because i assign the task of creating the meeting to the developer that brought up the point about 90% of the time the meeting invite never gets sent out.
now if i can only figure out how to pull the same trick with "that should be a class! why? we're never going to reuse it!" argument....
-
It all depends on what you mean by “correctly”. The sanest version involves pretending it's all done on bignums, as that makes integers have semantics that are very close to that of the mathematical integers, but I can understand why people might not like that (it's got non-trivial overhead, both in complexity and time).
Yeah, but it's hard to argue that any other way would be more "correct" in the general case. Faster and/or cheaper, sure. Either way, BenL-Go propaganda preempted, which is the main point
-
"that should be a class! why? we're never going to reuse it!"
My response would be "Tell me that in three months when we're reusing it" ;)
-
-
“Everyone, you know your colleague, Joe? Joe liked to do things like i+++++i. Joe isn't with us any more. Don't be like Joe.”
Now I think I'm going to add comments to my code to put the obfuscated version of the same thing. That would be even more confusing than just leaving the obfuscation straight in the code....
Other dev: well I understand this section, he's setting 'D' to 0 and adding 2 to 'o'... but why is the line before it //D= ++o-o++>>!0;;;; does he just inject random smilies into all of the code??
-
i+++++i
Assumingi = 0
before that line, the result of the expression is1
, andi == 2
.
And now I have to clean off the liquefied brain that's leaked all over my quills…
-
Assuming
i = 0
before that line, the result of the expression is1
, andi == 2
.$ /opt/cling/bin/cling ****************** CLING ****************** * Type C++ code and press enter to run it * * Type .q to exit * ******************************************* [cling]$ int i = 0; [cling]$ i+++++i; input_line_4:2:5: error: expression is not assignable i+++++i; ~~~^
Looks like it parses this as
((i++)++)+i
whichDEMSYR
so it gives up. (i++
is equivalent to((i = i + 1) - 1
which is not a variable an thus can’t be++
ed)Alternative parsing:
[cling]$ int res = (i++)+(++i); input_line_5:2:14: warning: multiple unsequenced modifications to 'i' [-Wunsequenced] int res = (i++)+(++i); ^ ~~ [cling]$ res (int) 2 [cling]$ i (int) 2 [cling]$
-
…and that, boys, girls, and others, is why you never write code like
i+++++i
-
Assuming i = 0 before that line, the result of the expression is
1undefined, and i ==2nasalDemon.FlyMyPretties().FTFY
-
Except it is actually a compile error (
i++
is not an l-value). Because the tokenizer is hungry.
-
That's why you stick with
++i+i++
if you're trying to be symmetrical.
-
Damnit I wanted that post to be 333 for the added layer of symmetry but Bulb hanzoed it.
-
Commas used in an ambiguous context are always parsed as separators, not the comma operator.
In that case, just wrapping parens around a builder pattern that uses operator,() methods would actually work as intended, so I am back to preferring that and impotently shaking my liver-spotted fist at all those kiddie cleverclogs and their fashionable crusade to overload every fucking thing in sight.
-
variadic templates
don't offer any reasonable way to do type safety, as far as I know. Using the builder pattern for a formatter should let a sufficiently obsessive-compulsive coder enforce type safety in the builder's long tail if the initial format function is handed a string literal.
I have no reason to assume that boost::format() is in fact as pedantic as that, but given that this is the loathsome builder pattern's only theoretical advantage over varargs, it fucking well ought to be.
-
Unless you only have one developer (and thus code reviews would be pointless), you save labor via code reviews.
No shit. I tried to get them implemented 18 months ago, when we had 3 devs. Since then we let one dev go, and I spent the next 3 weeks cleaning up her belgium code. Then 3 months ago, the other one quit, and I spent most of the following 6 weeks cleaning up his belgium code (I'm still not done with that, but priorities).
I've now been given the authority to implement code reviews once we bring on even one more dev. I've already set up TFS to require code reviews for anyone who isn't in the TFS admin group.
-
[variadic templates] don't offer any reasonable way to do type safety, as far as I know.
Err, and why not? Pretty sure you could write a function that translates from variadic templates to a builder pattern, and retain all type information. (Note: variadic templates, not varargs.)
Did you check out tinyformat? It's type safe, at least in the sense that attempting to "%s" a integer will print a string representation of the integer, and not random garbage because the int is interpreted as a pointer. Also from the tinyformat page:
tinyformat.h is a type safe printf replacement library in a single C++ header file. If you've ever wanted printf("%s", s) to just work regardless of the type of s, tinyformat might be for you.
-
and why not?
Most likely because I have no fucking clue what I'm talking about, which follows from an almost complete lack of motivation to wrap my head properly around C++.
-
Ah, carry on then.
-
I've already set up TFS to require code reviews for anyone who isn't in the TFS admin group.
Why exclude the admin group from code reviews?
-
-
Why exclude the admin group from code reviews?
Because they are Awesome and can do no wrong. Mind. Your. Own. Job.
Filed under: Using the reference while people can still remember the article, If you're reading this years later, hello. And how the fuck did you manage to do that on Discourse?
-
Why exclude the admin group from code reviews?
Because right now I'm the only dev and I'm in the admin group. Kind of
hardpointless to do code reviews by myself.
-
Not even the automated checks? Though I guess they're done in your IDE…
-
Not even the automated checks? Though I guess they're done in your IDE…
I just got the green light for code reviews, and you think I've had a chance to set up any automated shit yet? My, are you optimistic.
-
I didn't realise you only got the green light today
-
I didn't realise you got the green light today
Not today, but within the last couple weeks.
Do I need to emphasize the only developer bit again? I have tons of other shit I'm working on here.
-
Hmm… sounds like you may end up working a few weekends, and for that you have my sympathies