r/shittyprogramming • • Dec 01 '15

"We can't accept your pull request because it contains comments, which our style guide prohibits" - the Signal devs

https://github.com/WhisperSystems/Signal-Android/pull/4488#issuecomment-155830059
219 Upvotes

57 comments sorted by

38

u/AlGoreBestGore Dec 02 '15

Also keep in mind that if your first PR to the project is a 600-line complex change, it is very unlikely that it will be merged. I'd recommend starting with smaller easy changes to get a feeling for the organization and style of the code base, building up some shared understanding, and then trying to take on larger things after a few months of regular small contributions.

So basically do an internship before I can start contributing to your project?

46

u/[deleted] Dec 02 '15

Translation: It's a great pull request but we won't use it because we suffer from a superiority complex.

54

u/Sheepshow Dec 01 '15

These are A+ standard industry best practice Doxygen comments

+   * @param context Current context
+   * @param masterSecret Master secret
+   * @param threadId Thread id to cancel notification for
+   */
+  public static void updateNotificationCancelRead

12

u/milordi Dec 02 '15

It reminds me comments from JDK documentation:

/**
 * Gets the value.
 * @return the value.
 * /
public Object getValue()

15

u/crazybmanp Dec 02 '15

Sometimes Doc comments are difficult to write.

26

u/[deleted] Dec 02 '15

makubi 13 days ago

Hi,

I updated the PR according to your comments. Can you please have a look at it again?


moxie0 locked this pull request 8 days ago

Classy

37

u/cnelsonsic Dec 02 '15

Oh okay, I'll spend my nights and weekends on projects that actually want my contributions.

16

u/Reelix Dec 02 '15

public static void thisMethodIsCreatedToCombineTwoInputsToSimplifyStuffAndHasToBeNamedThisLongSinceImNotAllowedToCommentMyCode(string inputOne, string inputTwo)

4

u/PersianMG Dec 02 '15

Merged. Thank you for your contribution!

3

u/Dworgi Dec 02 '15

Append?

2

u/Fiech Dec 02 '15

In which case, I would say, ok, so long suckers and be on my merry way. No need to waste time with such people.

6

u/capitalsigma Dec 02 '15

Yeah it sounds bad out of context but I think this is totally legit.

1

u/Zambini Dec 02 '15
  • boolean bug130689NotificationFixEnabled = TextSecurePreferences.isBug130689NotificationFixEnabled(context);+ boolean hasWearSupport = hasWearSupport();

-13

u/[deleted] Dec 02 '15 edited Sep 21 '25

makeshift pen narrow badge kiss groovy caption tap test detail

This post was mass deleted and anonymized with Redact

39

u/vladdK Dec 02 '15

Comments can be used to explain why something is being done rather than what is being done. I don't want to name my functions

public void PutProcessingInNewThreadBecauseWeHaveTheMemoryAndCPUAvailableButAreLackingSpeed(List<int> data)

-19

u/[deleted] Dec 02 '15 edited Sep 21 '25

ad hoc gray amusing knee capable treatment toothbrush tan ancient memory

This post was mass deleted and anonymized with Redact

6

u/[deleted] Dec 02 '15

need to work with better co-developers.

Yes goyim, everyone has a complete choice in the other team members of the team they happen to work for.

7

u/lyons4231 Dec 02 '15

I wish I be as smart as you

2

u/[deleted] Dec 02 '15 edited Sep 21 '25

elastic simplistic meeting roll humorous worm scale crowd unique shocking

This post was mass deleted and anonymized with Redact

7

u/cheatatjoes Dec 02 '15

I do not understand the hate you're getting here. The point about cpu constraints may have obfuscated what you were trying to get across, but your actual point is clear and true: often comments become lies because they aren't updated as the code base grows. You cannot force a comment to be true.

Therefore, comments should be used sparingly to avoid lying to future devs while also relieving some maintenance overhead.

0

u/[deleted] Dec 02 '15

Thanks, I appreciate the comment. Like comments in code, I don't trust downvotes.

-9

u/RyGuy997 Dec 02 '15

The fact that it's fucking retarded

-2

u/[deleted] Dec 02 '15 edited Sep 21 '25

fly tart boast ancient repeat swim bag special test attraction

This post was mass deleted and anonymized with Redact

-1

u/lyons4231 Dec 02 '15

Not everyone is on the same skill level man.

1

u/[deleted] Dec 02 '15 edited Sep 21 '25

grey makeshift cobweb money person snatch consider command screw entertain

This post was mass deleted and anonymized with Redact

2

u/interfect Dec 02 '15 edited Dec 02 '15

I use comments to explain to me why I'm doing things. First I write down exactly what I want to accomplish, and why, as a comment, and then I write the code to do it. When I have to go back and change something, I read the comments to re-populate my head with all the considerations that went into designing the code in question. It saves time to not have to do all the design thinking from scratch.

How else do you tell the difference between intentional and accidental design decisions? Are you using an std::map, for example, instead of an std::unordered_map because of pre-C++11 habit, because you didn't want to write a hash function, or because having the items in sorted order is important in other code?

EDIT: Another thing I use comments for is pointers. If I'm going back to my old code and trying to get it to do something, it helps to have a comment on the DoTheThing method pointing towards the ThingDoerFactory that's supposed to be the real entry point.

-3

u/[deleted] Dec 02 '15

I don't care about the intentions of yesterday, I care about functionality. It's good to constantly review code, question the value, and propose new ideas.

Certainly don't put your thousands of ideas into a shared codebase.

0

u/crazybmanp Dec 02 '15

Man, people downvoting because the truly don't understand how to code are strong here.

0

u/[deleted] Dec 02 '15

[deleted]

0

u/stormcrowsx Dec 02 '15

I like your versions better.

I very much so like function comments but if you have to name your method something like what the original example is (if your function comment has to explain something that complex), it means your function is probably doing too many things and might lack reusability. Most methods should be explainable with the name and the comments I put in are the technical details/contract expectations it has. Such as "This parameter must be non-null and greater than 0 or an exception will be thrown"

A quick one line comment can let the reader know why you are moving it to a new thread when its called.

// Moving to a different thread to improve response
moveToNewThread(data);

8

u/erackron Dec 02 '15

If you look at the type of comments the author of the pull request added, it's (mostly) JavaDoc.

JavaDoc is almost always useful (perhaps not for a single class project), as it can be parsed to generate a searchable, comprehensive overview of the classes and methods which is very useful when:

  1. Using a library

  2. Getting to know the structure of an existing (complex) project

Moreover, JavaDoc is useful not only to document what a function does, but also elaborate on what exactly is expected of all the inputs and outputs of a function. Don't get me wrong, I am all for using descriptive naming for methods and arguments, but since the person thinking of the variable name might think the name is obvious knowing the meaning, the opposite might not be true for a different person not knowing the original intention of the writer of a method. This being only 1 example of a case where JavaDoc is very useful, but since it is late at night here I am keeping it at that 1 example.

1

u/[deleted] Dec 02 '15 edited Sep 21 '25

makeshift touch apparatus office adjoining lip person lunchroom license fuel

This post was mass deleted and anonymized with Redact

10

u/[deleted] Dec 02 '15

There's much more to programming than naming things. Explaining how something is structured can be very useful. There's no point in making whoever's reading your code understand how things work when you can explain it. The bytes those comments are composed of aren't expensive.

-3

u/[deleted] Dec 02 '15

There's no point in making people understand code when you can just read the comments? Are you kidding me? The first rule of code review is not blindly trusting the intentions of the creator. Your code reviewers absolutely need to understand how the code works at an operational level, not how you think it works.

You should constantly be understanding how the code works and questioning the value of the code. Don't trust comments.

7

u/interfect Dec 02 '15

Code review is just one use case. Most of the time when I personally am reading code, it's because I want to use a library, and I'm trying to make it do something weird. I'm trying to figure out if there's any parameter combination I can pass to a function to make it do such-and-such, or I've decided that I really need feature X and have dived down into the library to add it.

I don't have the time or inclination to read a book on the library's design, and often the book hasn't been written anyway. I want to look at the function I call to do my work, and get, from its documentation, enough of a picture of how it fits into the broader system so that I can figure out if such-and-such is possible to do with it, or work out what I would need to touch to add feature X.

It behooves me to be somewhat suspicious of comments, because often they are unmaintained, but if I can see at a glance a human-readable description of WTF is going on design-wise in a function, it can save a lot of reverse-engineering. Generally the authors of my libraries are not actively trying to trick me into contributing to their library wrong.

1

u/bro_montana Dec 02 '15

Most of the time when I personally am reading code, it's because I want to use a library, and I'm trying to make it do something weird.

Either you've never worked on even a moderately size project or there's no way that's true. How do you spend more time reading library code than all the other code that's around the code you're writing?

The vast majority of code is never once read in the form of a library.

3

u/WallyMetropolis Dec 02 '15

Comments are lies.

Seriously. How often do you find code that's been changed a half dozen times while the comments went untouched?

That said, I write terrible code and have to use a fair amount of comments, though I'm trying to more and more use unit tests as documentation.

2

u/romulusnr Dec 02 '15

The alternative is to write a dizzying myriad of nested classes and interfaces and factories for each of them in order to meet this pedantic sort of "style" requirement. In my opinion that makes the code harder to read because you can't actually possibly see the code in one place. You have to swim through a murky sea of classes, and you may not have enough air left to come back up after you finally unlock the treasure.

Of course, people who endorse such structure are also the sort that end up creating things like a FactoryGeneratorFactory.

1

u/WallyMetropolis Dec 02 '15

Good point. Certainly, doing things well is hard.

This kind of thing is partly what makes functional languages appealing to me. (And no AbstractFactoryGeneratorFactories are another, jeez.) Though of course FP languages have their own kinds of murk and dark magic.

I haven't found a way to break everything down into simple functions whose behavior and reasoning are immediately transparent. But it's something I strive for.

-1

u/lets-get-dangerous Dec 02 '15

I'm siding with the signal devs here. If you make ONE SINGLE 600 line change then you're not using git correctly in any capacity. This is the mark of a man who made one change, then another, then another, and then finally said "oh fuck I forgot I should have been committing these things as I went, fuck it".

This man is not your friend. He is your sworn enemy, and when he commits 600 lines of code and accidentally breaks something you'll have to either sort through every line or scrap the entire commit. Don't be this man. Commit in small increments.

And as a side rant: If you find that you frequently have to create comments to describe your code you should really spend some time learning about refactoring and naming conventions.

7

u/[deleted] Dec 02 '15

I haven't looked at this change, so maybe this particular one should in fact have been broken up, but there is no way you can make a blanket statement like "600 lines is too much for one change lol".

My first commit on my current project was over a thousand lines -- it was a big single feature which simply couldn't have been broken up into smaller chunks than that. I make plenty of one-line changes and plenty of thousand-line changes; there is a time and place for both.

And as a side rant: If you find that you frequently have to create comments to describe your code you should really spend some time learning about refactoring and naming conventions.

If you feel like your code is so obvious it doesn't need comments, you should really spend some time being forced to maintain decades-old comment-free code. Obviously the author of that code thought it didn't need comments either. (Of course, YOUR code is so perfect that it really doesn't need comments, unlike all of those other idiots who can't write clear code!)

-1

u/lets-get-dangerous Dec 02 '15

I usually don't say this but no, you're absolutely 100% wrong.

  1. If you can't break up a 1000 line commit into smaller commits you have no business programming. This isn't speculation, and I'm inclined to believe that you don't do this professionally because there's no way you would have a job if you tried to push a 1k line commit.

  2. I'm currently migrating software written in vb 6 and migrating it to .net, so yes I'm pretty well versed in reading old code that has no comments.

references for anyone who reads your post and has the misfortune of buying into it:

https://sethrobertson.github.io/GitBestPractices/ https://www.bignerdranch.com/blog/small-distinct-commits-say-you-care/ http://programmers.stackexchange.com/questions/74764/how-often-should-i-do-you-make-commits http://www.drdobbs.com/architecture-and-design/in-praise-of-small-commits/240166249 https://crealytics.com/blog/2010/07/09/5-reasons-keeping-git-commits-small/ http://blog.codinghorror.com/check-in-early-check-in-often/

7

u/[deleted] Dec 02 '15

I find it somewhat amusing that someone championing not writing comments is telling me that I have no business coding. Let's just agree to disagree, shall we?

0

u/[deleted] Dec 01 '15

[deleted]

14

u/northrupthebandgeek Dec 02 '15

I disagree. The point of well-written comments is not to say what a given piece of code is doing, but rather why said piece of code is doing it / is written in a particular way / etc.

Musicians (particularly symphonic/orchestral musicians, but this really applies in any environment involving sheet music) have a saying about marking changes in the printed sheet music: "A novice musician will never write in changes because he thinks he'll remember them; an expert musician will always write in changes because he knows he'll forget them". This philosophy holds very true with code; do you really trust yourself to remember things about your code when you inevitably have to fix bugs in six months?

4

u/Dworgi Dec 02 '15

Also, if something sucks and you know it, state what is preventing you from making it not suck. Eventually, that restriction might be gone and someone else could remove it.

4

u/[deleted] Dec 02 '15

Even if there's no real chance of something sucky getting fixed, it's still worth leaving a comment explaining why it sucks.

Otherwise, someone will eventually come along and say "Oh, THAT's how I'm supposed to do that! ...Huh. That's actually pretty ugly. Oh well, if it's good enough for $TEAMLEAD, it's good enough for me!". And before you know it the overall quality of your codebase is dropping. Just saying "Yes, this is ugly as fuck, I KNOW" discourages people from copying the style.

3

u/northrupthebandgeek Dec 02 '15

I personally throw TODO: dirty hack in places where I know the code is shitty and needs further attention sometime in the future, mostly as a reminder to give it that attention next time I'm looking at that code. If it weren't for at least that, there'd be a lot of shitty code hiding about with no indication of it needing fixed.

Now of course, the purist would suggest not leaving dirty hacks laying about (marked or otherwise), but unfortunately that's not always possible with a constrained timeline; sometimes you're dealing with an external but required dependency that's horribly written and opinionated and picky and uncooperative (I'm looking at you, Ruby on Rails) and you just have to make do with the "ugly but works" code until you have the budget to spelunk through Rails source and figure out what the fuck is needed to make the "correct" code actually fucking do what you want it. (</rant>)

27

u/interfect Dec 02 '15

I side completely against it. Looking at code can tell you what it's doing, but only comments can really tell you why.

Who wants to name their methods things like "reduceChildCountByTwoBecauseWeAlreadyAccountedForThoseChildrenWhenWeRebalancedTheTree()"?

5

u/romulusnr Dec 02 '15

I personally have a momentary mental seizure when I find myself about to write a class/method/property with a name over 30 characters. And then I remember, this is The WayTM and I should really just relax. Who cares if it causes every line it's used to scroll off the right edge....

2

u/crazybmanp Dec 02 '15

There are some cases where you should definetly include a comment on these tricky lines, but i side with their guide on its main point, excluding those kind of comments and doc comments for public (and even some private) methods.

1

u/alecbenzer Dec 02 '15

Yeah, I can see where their rule is coming from -- it's better to have code that' self-documenting instead of documenting itself when you can -- but there's only so much self-documenting you can do within the language without comments. Sometimes some more info will be necessary.

54

u/UlyssesSKrunk Dec 01 '15

That's just stupid as hell though to be honest. Unless they're asking for trivially simple code the rule makes no sense. Any code that's actually useful would have methods that would be better off being documented. Saying it's just not factored properly indicates that the person who wrote that section of the guideline is likely a novice coder at best if they think all properly factored code is self documenting, or put basically no thought into what they were writing.

12

u/erackron Dec 02 '15

Besides, adding (at least) JavaDoc is good since you can then generate an easy overview of your classes and methods that can be used to search/understand what methods exist in various classes so someone can more easily contribute. There's absolutely no good reason for omitting JavaDoc in Java code. The reason they mention doesn't invalidate the use of JavaDoc, it's a valid argument for enforcing the X amount of lines per method limit that you get when using Checkstyle for example.

0

u/[deleted] Dec 01 '15

[deleted]

10

u/crazybmanp Dec 02 '15

yea, or comments on lines that may do tricky things?

0

u/[deleted] Dec 02 '15

[deleted]

4

u/Euronomus Dec 02 '15

That's just it, a style guide that prohibits comments is a bad style guide. Yes there are tons of useless comments out there, but there are also tons of comments that are practically required for code to be understood without learning the entire codebase(and sometimes even then). Internal consistency with poor practices is no where as important as readable code.

6

u/Dworgi Dec 02 '15

I don't think that's true at all.

Some comments explaining reasoning are always better than none.

Yes, there are bad comments - auto-generated documentation style ones, for example - but comments as a whole are good.

3

u/romulusnr Dec 02 '15

Incidentally.... It's particularly not hard to filter out comments. Most modern IDEs will even do it for you.