Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Wait... So you got points off for doing your curly braces in the way of best practice? Give me a break
-
Yes, yes I do. And it fucking kills me. I'm also told that using 'break' or 'continue' in a loop is confusing for control flow. It was at that point I started playing Minecraft in class instead of note taking
-
I am aware good naming is important. It is not important to force your preference of prefix and capitalization onto me.
-
viat8547y@stevemk14ebr Pretend it's the codestyle of the existing codebase - you'll need to align to that going forwards.
-
devios157057yI'm with @stevemk14ebr. Coding style is like a person's accent. I say let people code how they want to code (when it's purely a matter of style), especially in school when you should be developing your own identity as a coder, not have to follow someone else's arbitrary rules. You'll get enough of that bullcrap in the workplace.
-
tmux20117yIf the rules were known before writing the code I think your professor is right on this one.
Maybe at some point you work for a company that actually enforces a specific coding style, and then what looks good to you not only won't matter much but will also get you in trouble.
You may think the professor is just a dick, bit there is a chance he tries to prepare you for real world situations. -
Bikonja23837yIf you were on my team and you were not following the team coding style I'd shoot you in the foot. If the convention has something that's bad, the convention needs to change. If yoi don't follow the convention you're what's bad. So yeah, this can be a good thing, but only if the professor told you that's how you had to write it. If it's just a generic programming class where you learn algos and stuff and the professor did not say that you beed to use a specific convention for his class than he's the one that needs to be shot in the foot.
With all that said, there's things that are better/worse and things that people prefer. Using different sizes for indentation is a preference. Not indenting is worse.
And it's not always easy to spot reasons why something is better as opposed to being a matter of preference. Like you might think it's a matter of preference whether you explicitly put brackets around expressions to group them, as long as you keep in mind what the order of execution is. But consider someone comibg to your code to add another expression and trying to figure out what the order should have been. Even if that person knows what the correct order is, they might not be sure if you wanted that order or did you think it would execute in a different order.
Now, it's tempting to say I'll put the opening braces on the same line as if because I like that more, but maybe putting them on the next line has an actual reason that it's better. Even if it looks better on the same line to you.
"Looks better" is not a valid reason to say it is better. To me, it looks better one a new line, but I follow the conventions so when I'm doing C# I put it on a new line, but when I'm doing JS I put it on the same line. -
Levy557yIn my opinion there is a difference between "I'd like to place a \r\n before / after brackets" and "leaving a while loop is better than using a huge if condition". First thing is important when working in a team of programmers. Second sentence is referring to the thing called "CleanCode" as well as the function names do.
https://amazon.com/Clean-Code-Handb...
It's quite interesting to read and tbh - I adapted some aspects of clean code to my every day coding behaviour :D -
th3113247y@stevemk14ebr Unless it's a super short obvious function, break and continue can definitely be absolutely terrible. Make your loops correctly and you won't need them. To me it's so much better if a function always ends at the bottom, not conditionally somewhere arbitrary.
Ignoring more experienced people and playing a game does come across as quite immature and probably won't get you very far in this industry. -
devios157057y@Fydrenak it 100% depends on the situation. I've run into lots of situations where while (true) combined with break and continue is the simplest and most concise way to represent the needed control flow. Forcing yourself to use the loop's condition when it doesn't make sense to is not going to do anything good for your code, so teaching it as though it's a law is just plain wrong imo.
-
devios157057yRemember, code is a tool. It bows to you, not the other way around. You should learn how to do things in lots of ways; don't just follow arbitrary rules your whole life never questioning why. It'll also help you when you need to understand someone else's code who may not have followed the same rules.
Conventions and standards are important, but don't get so locked into them that you forget you can actually do things other ways, too. -
HnDev12427yI take points of my students when they use different coding styles within the same codebase. And when they have their indentation messed up.
-
th3113247y@devios1 I do agree pretty much. Sometimes there's just that one annoying case that needs to exit and it's the cleanest way to do it. Albeit only if adequate commenting is given.
But if you teach these things as flexible then I imagine people would be more likely to overuse them. If you teach it strictly, then someone will only use it when they truly believe it to be the best solution to a problem. There are no laws of course, but thinking you're better than almost laws while still in school is a bigger problem.
I really do think that if you ever use one, you should try and think of a clearer flow of control that doesnt need it though. I do agree with you, I just wanted to elaborate a bit :) -
th3113247yI had an insanely strict coding style in university, if we used break (outside of a switch) or continue in any of our work we would be given a 0. This was in c++ not that it really matters. There aren't very many cases where you need it and the ones that exist aren't like to come up on a uni project.
While this is a little bit crazy, it did teach me the importance of good program structure, and when I break these rules I always make sure to have a damn good reason to do so. -
devios157057y@Fydrenak
> Thinking you're better than most laws while still in school is a bigger problem.
Fair point! Obviously teachers still have a job to do and it's important they teach good habits. But sometimes it can just end up being their personal preferences.
Also I absolutely agree you should always try to find the best approach to each problem. Using break and continue purely out of laziness is not excusable. Considering multiple approaches and weighing their pros and cons is hugely valuable for learning good coding habits. -
I just follow the language defualt style. I mean:
Python: var_name
Java: varName
C#: VarName
... -
devios157057y@Alireza6677 Good lord, even C# doesn't use PascalCase variable names. Surely you mean methods.
-
@devios1 Actually i never used c# but if someday i have to use it, i just follow the default. Every language looks nicer with it's default style.
Thanks for noticing.
Why the fuck do teachers take points off for coding style. Like really placing my open house brace on the same line as an if is what looks good TO ME. And breaking from a while loop with an inverted condition is nicer than a huge if TO ME. Fuck it I like the m_ for member variables too. And yes C++ usually names functions like someFunction, but I like how c# does SomeFunction. Like shit, it's personal I don't care that I lose 5points every test I do it just to say fuck you
undefined