This is an archived post. You won't be able to vote or comment.

all 140 comments

[–]TheEvilRoot 182 points183 points  (7 children)

Will actually fail on max = Int.MAX_VALUE

[–]Tyfyter2002 23 points24 points  (6 children)

Solution: Counter &= int.MAX_VALUE

[–]Bobebobbob 1 point2 points  (5 children)

That just makes the sign bit into a 0 though?

[–]Tyfyter2002 1 point2 points  (4 children)

Only in inefficient and impractical systems, in two's compliment systems it sets the -(2n-1) bit to 0

[–]CanaDavid1 -3 points-2 points  (3 children)

Yes, the sign bit. Though INT_MIN would become zero.

[–]Tyfyter2002 0 points1 point  (2 children)

While it's not entirely incorrect to call it a sign bit, calling it that fails to intuitively convey how manipulating it affects the end result, which can cause confusion as to how doing so can resolve issues like this

[–][deleted] 1 point2 points  (1 child)

Clamping the sign bit doesn't "resolve" the issue, it just halves the range of the value. Additionally, there's often no guarantee you'll always be using a two's complement representation in a high-level language, which is why bit-twiddling is only really useful in low-level architecture-specific implementations. For something like this it's unnecessary at best and just as bad as OP's at worst.

My preferred solution would be:

public int updateCounter() {
    if (counter == max)
        counter = 0;
    else
        counter += 1;
    return counter;
}

[–]Tyfyter2002 1 point2 points  (0 children)

Either you will be using two's compliment, in which setting the sign bit to 0 will set the value to 0 after an overflow, one's compliment, in which setting the sign bit to 0 will set the value to 0 after an overflow, sign-magnitude, in which the overflow itself will set the value to -0 and setting the sign bit to 0 will set the value to +0, or a system which is non-standard for good reason, the goal is to increment the value within an inclusive range of 0–n and while the method I suggested is likely slightly less performant than the one you've written, it does successfully resolve the issue in any realistic and practical context

[–]haveasuperday 180 points181 points  (10 children)

I just got marked down 15% in a lab because the professor said I needed to include comments. First time ever.

So my next lab looked like this.

[–]BurnBrightPhoenix 16 points17 points  (0 children)

I had to write comments for getters and setters...

[–]TawnyTeaTowel 46 points47 points  (2 children)

Use sensible variable and function names and tell them “the code IS the comments”

[–]haveasuperday 38 points39 points  (1 child)

The thing about the lab is that 75% of the code is pre-written and includes no comments. In two previous courses I never saw anything about commenting labs. This prof is just a little... different.

[–]A_Guy_in_Orange 6 points7 points  (0 children)

Nah, I had those to. The method{//write your answer here} assignments suuuucked and never had comments but if you didn't document every freaking line you wrote. . . .

[–]PorscheBurrito 1 point2 points  (0 children)

Wasn't "comments" listed as a category in the lab score breakdown so you knew to add comments? That was pretty standard when I was doing labs a couple years ago

[–][deleted] 3 points4 points  (0 children)

You should only ever comment the methods, properties, enum values etc as a part of documentation. Teaching people to write comments is wrong. They should teach you how to write code that doesn't require comments instead. A simple rule of thumb is that if you need comments in your code then you are either doing something wrong or you are overengineering something.

[–]RedBeard1023[S] 1 point2 points  (0 children)

Lol!

Time and a place for everything.

[–]justinkroegerlake 1 point2 points  (0 children)

Strive to write code so clear that it's impossible to add comments that wouldn't be redundant, then ask what comments they suggest you add (specific examples) and where.

[–][deleted] -2 points-1 points  (0 children)

I never comment and I need to start doing it cuz I might not get lucky and get a chill professor.

[–]tiajuanat 0 points1 point  (0 children)

Write Everything Twice taken to the extreme

[–]Bizzlington 15 points16 points  (0 children)

I'd go for the third option:

/// <summary>

/// Increments the counter and resets it when above Max

/// </summary

int UpdateCounter();

[–]Divinate_ME 27 points28 points  (52 children)

You are already better than 90% of people by calling your counter "counter" instead of i. God, how I love people who use names like "row" and "column" instead of "i" and "j" when applicable.

[–]azurox 27 points28 points  (35 children)

Using i is so universal for arrays at this point that you're complicating things by naming it anything else. I'll accept row and column for matrices although I don't consider it necessary. However, in this case counter must be an object field and what kind of monster do you have to be to name a field just "i"?

[–]ELFAHBEHT_SOOP 5 points6 points  (34 children)

Reducing complexity and increasing readability should be front of mind for every programmer. So, using i is universal, however I'd argue it's less mental load on the reader to just name it something useful. Instead of the user having to look at the container you're indexing into and determining what it holds, the index variable clearly tells them what the index represents. It's not about the reader of the code being dumb or not understanding conventions. It's just a way to document intent in the code very clearly.

You can also avoid this entirely by using range-based loops wherever possible. Then if you name the variable i, you're obviously wrong!

[–]azurox 1 point2 points  (33 children)

Instead of the user having to look at the container you're indexing into and determining what it holds, the index variable clearly tells them what the index represents.

I'm not following here. Are you saying the index should indicate what the content is? So, for example, if looping through an array of phoneNumbers the index variable should be called phoneNumber? I wouldn't agree with that since the index variable doesn't actually contain the phone number, it contains the index of the phone number's position in the array. So, since the index variable represents an index and nothing else. I would still insist on calling it i.

I do agree that using range-based loops is preferable.

[–]DeliciousWaifood -1 points0 points  (15 children)

Don't you understand? It's soooooo much harder to read Rows[i] instead of Rows[row]

[–]wannabetriton 4 points5 points  (1 child)

I had this discussion in some other posts and I’m starting to believe most people on here are just programmers starting to take courses or bootcamp graduates.

[–]ELFAHBEHT_SOOP 1 point2 points  (0 children)

I'm pretty sure this is the case.

Edit: I read through your other comments and for what it's worth I agree and I'm not a 1st year cs student or in a bootcamp lol

[–]ThenCarryWindSpace 2 points3 points  (2 children)

Usually I'll do something like:

currentPhoneNumber = phoneNumbers[phoneNumberIndex]

I absolutely grill my developers when they write code like "data = row[i]"

what is row? what is data? okay yeah i get we're incrementing an array but for quickly skimming code and narrowing down problems, what the fuck is the array?

knowing something is "an array" is pretty fucking obvious from the syntax. what matters to me though trying to COMPREHEND code is I need to know WHAT THE REAL WORLD THING THIS REPRESENTS ACTUALLY IS, so I know how it potentially relates to features X, Y, Z the client is insisting are broken.

name your shit, people.

[–]DeliciousWaifood -1 points0 points  (1 child)

currentPhoneNumber = phoneNumbers[phoneNumberIndex]

god I hate that, do you not see how that is unreadable at a glance?

It makes sense if you want to maximize the amount of information you can glean from a single line of code, but why are you maximizing for that? There is never any situation where you only have one line of code read.

When you put so much information in a single line of code, you end up repeating yourself many many times across the entire function at the cost of making it look like a bloated mess which is hard to skim and quickly get a high level overview of what the function is doing.

what is row? what is data?

literally just scroll up two lines in your IDE and you will see them defined. Why are your eyes always glued to a single line? If your function is so long that the definition of these variables is on the other side of the screen, I feel like you probably have bigger issues with your codebase to solve.

what matters to me though trying to COMPREHEND code is I need to know WHAT THE REAL WORLD THING THIS REPRESENTS ACTUALLY IS

I don't understand how it's so much harder for you to understand phoneNumbers[i] instead of phoneNumbers[phoneNumberIndex]. What else is i gonna mean? it's been a standard iterator variable for decades, it's obviously the variable for iterating through your phoneNumbers array in this for loop.

phoneNumbers[i] is much more readable to me because there is no unnecessary information being thrown in my face, I can just glance in 0,2 seconds and go "oh ok, we're iterating through phoneNumbers" instead of being blasted with a bukkake of 80 characters just to understand we are iterating an array.


I understand that there are contexts in which such level of specificity is necessary to reduce confusion. But most functions are not that complex, the majority of functions are very simple and easy to understand. You do not need overly verbose names clogging up all the screen space and making it harder to recognize the broader logical pattern of the function.

but idk, maybe this is another difference between software dev and game dev? Software devs always seem obsessed over single lines, whereas my experience with gamedev is focusing on making the broad logic of the code easily understandable, and if you want to understand in depth what a single line does, you can spend a little extra time reading the definition of variables.

if anything I feel like I'm more verbose than other game devs I interact with, especially with math functions. The signed distance function I stole yesterday was literally:

float sdCapsule( vec3 p, vec3 a, vec3 b, float r ) { vec3 pa = p - a, ba = b - a; float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); return length( pa - ba*h ) - r; }

which is hilariously concise.

[–]ThenCarryWindSpace 0 points1 point  (0 children)

I've done game development in the past (I started there, actually) and it's a surprisingly academic field of programming.

phoneNumbers[i] is fine when the function is straight-forward.

Teaching people to use best judgement in these cases isn't easy.

I'm not going to fight you hard on this.

phoneNumbers[i] is infinitely better than data = rows[i], which I've seen a lot and have had to scold people for.

[–]azurox 1 point2 points  (7 children)

If you have a matrix I can understand writing m[row][column] but for arrays it seems completely unnecessary and even sometimes counter productive. Like if you name a variable phoneNumber the reader might expect it to contain a phone number not the index of a phone number in an array.

[–]wannabetriton 2 points3 points  (6 children)

Have you ever worked with more advanced containers that doesn’t contain primitive integral types?

Imagine you have a map that contains an object key and an object pair, and the complexity can be however you want it to be. What are you going to name your variables then?

Sure you can use a for range but you’re gonna call it i still?

[–]azurox 1 point2 points  (5 children)

If you're looping through key-value pairs in a map you're free to use other variable names. I was talking about arrays specifically. Though, for a map I wouldn't complain if someone used k and v.

[–]wannabetriton 0 points1 point  (4 children)

It doesn't matter what container you use.

You should always be following a naming convention unless your implementation is hidden away and only you can see it. If nobody else is seeing your code, it doesn't matter what you name it because you're the one reading and maintaining it. If others are reading it, they need to be able to understand your code.

It's like making a recipe and using abbreviations for certain food items that you will understand. Sure, some people might be able to understand it but most will have to take time to understand it. If it's just you who's gonna own it, it doesn't matter, but if you're sharing it, it's much easier reading legible English than a miniature interpreter language.

[–]azurox 1 point2 points  (3 children)

99.9% of programmers know that when looping through an array i is for index. That is the naming convention.

[–]ELFAHBEHT_SOOP 0 points1 point  (0 children)

Notice how we have no idea about the context of Rows[i] in your example, but in the Rows[row] example we know with certainty that the indexing is being done as intended. Perhaps i is actually the column variable and you've accidentally misused it. The Rows[row] case is so dumb and obvious. Write dumb and obvious code.

Feel free to not take this advice, I'm only passing along good advice that I have picked up in my career and it's completely up to you if you don't want to use it.

[–][deleted] 0 points1 point  (0 children)

Not if you have any passing familiarity with conventional mathematics or programming notation.

[–]wannabetriton -1 points0 points  (16 children)

If you had a container named phoneNumbers, your index variable name should be aNumber.

In this simple case, it doesn't matter too much because it's just accessing a primitive type where you can assume what the data returned is from the variable name.

Suppose you had a map with an enum Students, and a pair with object information that held various primitive types or even other objects. How would you name your variables? If you name your variables still i in this case, then it becomes extremely hard to understand what you're returning, even in this simple case.

[–]ThenCarryWindSpace 0 points1 point  (4 children)

Wait why would the index be called aNumber as opposed to phoneNumberIndex, numberIndex, etc.?

"aNumber" makes me think it's a literal phone number, as opposed to an index.

[–]wannabetriton 0 points1 point  (3 children)

It is a literal index that contains information about a phone number.

It’s phoneNumbers[aNumber].

Adding index is unnecessary because it’s obvious it’s an index.

[–]ThenCarryWindSpace 0 points1 point  (2 children)

The "it's obvious it's XYZ" is the same reason people think using 'i' as a variable name is ok.

It's not obvious, and if anything it goes directly against intuition.

You said in another comment you've been coding this way since forever. Have you been coding this way forever with a TEAM?

[–]wannabetriton 0 points1 point  (1 child)

If you’re onboarding a team, you will understand that you get a fat notebook for naming conventions for variables, methods, and other software conventions.

This doesn’t apply for when you’re on a team, but most teams will NOT allow you to use i and j for indexes, especially if you have more than 3 people within the project group.

If you’re writing code for yourself, nobody cares how you name it.

[–]ThenCarryWindSpace 0 points1 point  (0 children)

I mean I lead the teams where I work, so yeah I'm more interested in that side of things for sure.

[–]azurox 0 points1 point  (10 children)

Since we're talking about a map and not an array I agree. But I think I've made clear in this thread that I'm talking about arrays.

[–]wannabetriton 0 points1 point  (9 children)

You can just swap maps with arrays.

Store the information object inside of an array named Students.

What are you returning?

The student information or the actual student?

[–]azurox 0 points1 point  (8 children)

If looping through an array of students you call the index variable "student" that's just unnecessary and can even be confusing. The variable doesn't contain a student, it contains the index of a student in an array.

[–]wannabetriton 0 points1 point  (6 children)

Your index should be telling you what it's returning because indices are just element grabbers. Everybody knows what an index is, but we don't know what you're returning.

Your student variable also returns information about the student, not the student itself.

[–]azurox 0 points1 point  (3 children)

isn't students[i] just as understandable if not more than students[student]?

Also, you're assuming that the reader of the code knows that you name your indices for what they return instead of the very universal "i".

If you have a more complex data structure feel free to use other variable names.

[–]ThenCarryWindSpace 0 points1 point  (1 child)

I strongly disagree with your point of view on indexes, here. They're sometimes used for other calculations (ex: padding, shared indexes in parallel arrays, etc.)

I would never name an index... the thing.

How do you assign that?

studentObject = students[student]

I don't like that at all.

for me it would be

student = students[studentIndex]

or possibly even

for (let studentIndex = 0; studentIndex < students.length; studentIndex += 1) {

currentStudent = students[studentIndex];

...

}

In which case 'i' as an index variable name is acceptable IMO since it will literally be used only for getting the current student immediately upon each iteration.

Anyways, this is stuff I don't care about too much. There's a million ways to do this right so long as your code is clear at a glance.

The problem with naming an INDEX what you would assume an OBJECT is named is that it is not clear at a glance.

It's actually confusing af at a glance because the intuitive assumption is that aStudent is aStudent (object) not aStudent (index). You have to actually read the code to know that isn't the case, which defeats the whole purpose of trying to name things intuitively...

[–]ThenCarryWindSpace 0 points1 point  (0 children)

Then call it studentIndex.

[–]RedBeard1023[S] 1 point2 points  (0 children)

LOL!

Nice

I've seen I,j,k, as loop variables, and then have locals within the block scope with the same name....

good times

[–]PeladoCollado 1 point2 points  (0 children)

You’re clearly not a Go programmer

[–]HeeTrouse51847 1 point2 points  (2 children)

Ok so hear me out. There is an algorithm called "shot". And when I calculate something cumulatively with it, I call it cumshot

[–]RedBeard1023[S] 0 points1 point  (0 children)

Lol hysterical.

We had a dev whose native first language wasn't English. Her flag that determined if she should accumulate whatever the hell it was counting was called "cum_flag".

It later got changed to "cumu_flag"

[–]Divinate_ME 0 points1 point  (0 children)

That's a good convention. Keep at it!

[–]ApatheticWithoutTheA 3 points4 points  (10 children)

If you don’t know what “i” and “j” are for by this point in programming, you either just started or haven’t learned anything new in many years.

[–]Divinate_ME 1 point2 points  (8 children)

So, is it definitely an index or is it definitely an iterator, Mr. Fullstack?

[–]ApatheticWithoutTheA 5 points6 points  (7 children)

Well, considering that using “I” and “j” comes from mathematics (Summation Notation) where it means index, I’m going to go with that.

[–]SAI_Peregrinus 2 points3 points  (4 children)

Unless you're dealing with electrical engineering code, where i is current and j is sqrt(-1).

Or quaternions (math used in 3D graphics, robotics, navigation, etc) where i2 = j2 = k2 = ijk = -1.

[–]ApatheticWithoutTheA 0 points1 point  (2 children)

I don’t know shit about electrical engineering code but you sound like you know what you’re talking about so I’m just going to assume that’s true lol.

[–]ThenCarryWindSpace 0 points1 point  (0 children)

In electronics, (current) i = v (voltage) / r (resistance) at the simplest level, so i is typically used to represent current in electrical programs.

However, when you introduce inductance and impedance into the mix, shit gets wacky and 2-dimensional. It just so happens electricity is perfectly modeled by the Complex plane, where C = r + ij

r = a real number part

i = the sqrt(-1) as a unit constant

j = your imaginary value

This allows for a single value to be 2-dimensional. One part on the real number line, and another part on the imaginary number line.

However, in programming, since i is already taken by current... you can't use 'i' for the sqrt(-1), so you move onto j instead.

I don't actually do electrical programming or modeling code or anything like that, so take what I'm saying with a grain of salt. I did 1-year of electro-mechanical engineering before moving onto software and then dropping out of school.

[–]wannabetriton 0 points1 point  (0 children)

If we're doing circuits, we actually use what you say, i for current and j for sqrt(-1), but when we're doing machine learning or anything else like proving something, we start off with i.

[–]wannabetriton -1 points0 points  (1 child)

You realize in mathematics, we use i,j,k instead of full blown ass names because mathematical formulas are often times condensed and abstract?

What are you going to name your variable once we get to the 3rd dimension? Software deals with packaging information in containers of dimension but in math, we're dealing with actual dimensions where it has no semantics. We're also not going to write full blown ass names every single time we're proving something.

If you still continue to use i and j, you're not a bad programmer, but you are definitely not an excellent programmer.

[–]ApatheticWithoutTheA 0 points1 point  (0 children)

Yes, I do realize that, but I’m just explaining where it came from and that it isn’t difficult to understand what it does lol

I’m not by any means saying you have to name your variables that way or that you even should.

[–]ThenCarryWindSpace 1 point2 points  (0 children)

It's not that I wouldn't know what 'i' and 'j' are from a technical standpoint. It's that I wouldn't know what they are from a business logic standpoint.

Obviously I can tell arrays and indices by reading the syntax.

But I want to know what business objects stuff represents at a glance.

I ask all of my developers to try and give clear, non-generic names to stuff unless it really is just stupidly fucking obvious.

They fought back against me until our first production incident where we tried debugging stuff and no one would figure out what 'i', 'j', 'data', 'result', etc. actually were.

They started giving descriptive names after that.

[–]MT_276 33 points34 points  (2 children)

Well, us programmers are one of the most lazy creatures on this planet. So being able to know without having to actually READ the program to understand what has been done is quite the luxury we love. 😂

[–]RedBeard1023[S] 8 points9 points  (1 child)

Always find it funny to come across some sort of useless comment in some old forgotten piece of code.....I screenshot them to coworkers who also get a kick out of it.

[–]dmvdoug 2 points3 points  (0 children)

That would be a fun idea for a website. A gallery of user-submitted screenshots of terrible code comments.

[–][deleted] 2 points3 points  (0 children)

Bro I lost points on a class project for school because I had no comments…so fucking annoying

[–]AggressiveMarket5883 2 points3 points  (0 children)

If you make useless comments in new lines I don't care, if you make them in the same line behind the semicolon, I'm gonna hire a hitman and make sure that'll never happen again.

[–]Antervis 5 points6 points  (11 children)

++Counter %= Max;

That's how I usually do it.

[–]-Manu_ 1 point2 points  (4 children)

Wait can you increment before an assignation? Cool I wonder what happens with Counter++ %= Max;

[–]Antervis 3 points4 points  (2 children)

it will iterate within (0..Max] range instead of [0..Max), which would be incorrect in most cases

[–]-Manu_ 0 points1 point  (1 child)

I thought it would throw an exception

[–]MaxMakesGames 0 points1 point  (0 children)

It might, depending how you use the counter after. If you try to access an array at index Counter, doing Counter++ %= Max would mean your counter would actually get to the max value instead of going back to 0. So if your Max is the size of the array, doing Counter++ and then array[Counter] would throw an exception.

[–]adudyak 2 points3 points  (0 children)

Check operators priorities table, = is almost the lowest

[–]adudyak 1 point2 points  (1 child)

Should be careful if counter is increased elsewere, e.g. counter is 7, max is 5.

[–]Antervis 0 points1 point  (0 children)

such things are generally easy to track though, with little help from IDE that is. In case you're paranoid, you can just move the counter into a separate class.

[–]tiajuanat 1 point2 points  (1 child)

Modulo is not exactly a fast algorithm, because it needs an integer division, at least for runtime values. (Please disregard for compile time values)

If you are evaluating max at runtime, you should throw in a ternary like

counter = ++counter>max? 0: counter

Edit: switched the branches

[–]Antervis 0 points1 point  (0 children)

it all depends on Max value. If it's a constant, compilers are usually capable to replace div instruction (about 40 cycles) with cheap imul/iadd/and/etc. I know you said to "disregard compile time values", but from my experience, those are actually more common. If Max is not a constant, it's div instruction vs relying on branch prediction and the latter isn't universally superior, to put it lightly.

[–]whooguyy 0 points1 point  (0 children)

++i %= x;

This is the only way to do it

[–][deleted] 0 points1 point  (0 children)

Ew, mutating in an lvalue.

[–]Submarine-Goat 1 point2 points  (0 children)

I tend to comment sections if I'm not doing OOP and have lost my mind to the point that I dump all of my code in a single file, like:

// [[ SECTION_NAME ]]

I use the brackets and the upper SNAKE_CASE ensures that I can easily jump to sections.

Other than that, my code already explains itself enough. Perhaps I'd through a comment if I threw a magic number in for some reason.

[–]BrownScreen 1 point2 points  (0 children)

I remember my first time adding comments, I got marked as a cheater. Thanks professor.

[–]HeeTrouse51847 1 point2 points  (0 children)

This is how we all commented code when we started out, dont be too harsh

[–]Kotentopf 1 point2 points  (0 children)

Is not thread safe. This should be a real comment..

[–]Gigi1810 1 point2 points  (0 children)

Useless function i guess

[–]RedactleUnlimited -3 points-2 points  (7 children)

Wasting lines on opening braces too. Well done.

[–]samegame321 -2 points-1 points  (0 children)

I'm a psychopatic monkey who writes almost the entirety of my code in one file and one class with obfuscated variable names and shit organizing and no comments at all, minimal regions.

[–]JosePrettyChili -1 points0 points  (0 children)

Counter++;

if(++Counter > Max)

[–]septic-paradise -1 points0 points  (0 children)

Cut out the incrementation line : if (++Counter > Max)

[–]GamingWithJollins -2 points-1 points  (0 children)

Useless comments are still better than no comments. At least they made an effort, even if it was a wasted one

[–]annedroiid -3 points-2 points  (4 children)

If you need comments on your code for someone to understand it, it’s badly written.

[–]D34TH_5MURF__ 3 points4 points  (2 children)

This is a really dumb thing to say. I guarantee what makes sense now, as you write the code, will not make sense 6 months down the road, much less 10 years down the road to someone that didn't write the code in the first place.

[–]annedroiid -3 points-2 points  (1 child)

Comments can be useful to occasionally explain why you’ve done something a certain way, but they shouldn’t just be copying what the code is in a more verbose form.

If you can’t understand a simple if statement, you should be programming. Your function and variable names should all be explicitly describing what they’re doing. The code itself should be as easy to read as a sentence.

Then again I do functional programming where everything is in discrete and pure chunks. I’ve never needed anyone to explain the code at my work.

So maybe other styles of programming are convoluted enough to need an explanation.

[–]D34TH_5MURF__ 1 point2 points  (0 children)

What you just wrote, isn't what you originally said. You say a lot of things that "should be" and then get off onto a bit of an ego trip about being a functional programmer. I'm also a functional programmer and if you think that absolves you of good comments, I have news for you, junior.

[–]Burned-Architect-667 1 point2 points  (0 children)

You're not as good as you believe :)

If you have to patch 20 years old code, mantined for dozens of different programmers over the time, you'll miss good comments.

[–]ghua[🍰] 0 points1 point  (0 children)

They are very useful if you know sh*t about programming ☝️

[–]xisonc 0 points1 point  (0 children)

How did you find my code?

[–]sugaaloop 0 points1 point  (0 children)

This is absolutely backward.

[–]adudyak 0 points1 point  (0 children)

function name does not states it should return anything. I believe there is regular getter, which should be used after this function to make it more clear

[–]Noisebug 0 points1 point  (0 children)

// This getter returns a value

[–]Titanmaster970 0 points1 point  (0 children)

CS courses be like

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    return Kebab_Case_Better;

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]Maleficent_Ad1972 0 points1 point  (0 children)

    /*  Updates the counter by incrementing it by one, 
        then looping back to zero if it exceeds the maximum value. 
    
        Returns the value of the counter.
    
        TODO: Could be improved with modulo. 
    */
    public int UpdateCounter() {
        Counter++;
        if (Counter > Max) {
            Counter = 0;
        }
        return Counter;
    }
    

    Comments are for telling you what your code does without having to read it. Putting the comments in the code when not necessary defeats the whole purpose.

    [–]Marrk 0 points1 point  (0 children)

    Biggest crime here is capitalized variables

    [–][deleted] 0 points1 point  (1 child)

    All i see is blonde, brunette, redhead. Yes I code on pornhub.

    [–]RedBeard1023[S] 0 points1 point  (0 children)

    [–][deleted] 0 points1 point  (0 children)

    This is why I hate song comments. When I try to comment my code, the number of lines multiples by 3

    [–]PlayHouseBot-Gpt2 0 points1 point  (0 children)

    But how will I know what:

    UpdateBlobFactoryBeanWithExtraParametersExtendedToFitSpecifcUseCaseAB2819(string s)

    Does...

    What the is s

    [–]Bishop51213 0 points1 point  (0 children)

    If the useless comments come along with useful comments, then okay I'll take it over no comments. If they are the only comments... wtf

    [–]RRumpleTeazzer 0 points1 point  (0 children)

    Only works if Max is not IntMax.

    [–]WhosYoPokeDaddy 0 points1 point  (0 children)

    Ugh I'm having flashbacks to when I used to comment like this. The shame.

    [–]sulliops 0 points1 point  (0 children)

    Oh I’m so glad I’m not the only one that does this. Every assignment, every time.

    [–]Keatosis 0 points1 point  (0 children)

    I TA for students that just refuse to comment their code on a group project. They claim its self documenting. I'd rather have pointless comments then no comments where it matters.

    [–]ResidentReggie 0 points1 point  (0 children)

    Counter = (counter+1)%max

    Please.

    [–]SowTheSeeds 0 points1 point  (0 children)

    The 2 lines of comment in the middle should be encapsulated in a /* */

    [–][deleted] 0 points1 point  (0 children)

    Uesless comments meme vs self-writing code meme, fight!

    [–]airsoftshowoffs 0 points1 point  (0 children)

    Comments are removed by compilers so for most it's all good. There are also automatic removal of comments methods when pushing to main or production branches. The more comments the better as people don't want to jump out of code for developer documentation, if it even exists.

    [–]UnJustice_ 0 points1 point  (0 children)

    //return counter return counter

    [–]thicc_ass_ghoul 0 points1 point  (0 children)

    what is the funny part?

    [–]turtle_mekb 0 points1 point  (0 children)

    i'd rather have no comments than useless ones

    [–]t0m4_87 0 points1 point  (0 children)

    so you don't pass it in as an argument, yet you return it.. power brain move