|
Gordon Cole posted:If you're really worried about how long it takes to type out stringBuilder, take some typing lessons. And if you're working in an environment without autocomplete you're doing something wrong. It was a revelation for me that eclipse uses capital letters to search through camel cases, as a shortcut. So to autocomplete SomeFooBarThingActivity, anything unique from SF through SFBTA or even SFBarTA or SFBTAct will match in additional to the normal prefix matching. It can really speed things up without loss of meaning in the class name! Not that I'm advocating for rambling class names, of course.
|
# ? Nov 23, 2012 10:27 |
|
|
# ? Jun 5, 2024 05:33 |
Wheany posted:"tmp" is pretty much the worst name for a variable ever. code:
|
|
# ? Nov 23, 2012 10:42 |
|
c
|
# ? Nov 23, 2012 10:51 |
|
Wheany posted:"tmp" is pretty much the worst name for a variable ever. In python I tend to use this trick to make 2D arrays a lot (well, until I discovered object.__getitem__(self, key) allows tuples, so it's beneficial to make a 2DArray class that handles them so you can access members using [x, y] instead of [y][x] like a normal 2D array): Python code:
|
# ? Nov 23, 2012 11:02 |
|
Wheany posted:"tmp" is pretty much the worst name for a variable ever. I see you and raise you "test"
|
# ? Nov 23, 2012 11:09 |
|
Jewel posted:In python I tend to use this trick to make 2D arrays a lot (well, until I discovered object.__getitem__(self, key) allows tuples, so it's beneficial to make a 2DArray class that handles them so you can access members using [x, y] instead of [y][x] like a normal 2D array): row is a better name here and you might as well just use numpy for this since they've done all the nice fancy ndarray things already.
|
# ? Nov 23, 2012 11:12 |
|
It's hard to find any code that doesn't use 'tmp' or 'temp'. Just 'find|xargs grep' through my code folder and cURL, SQLite, LAME, Boost, Sourcemod, HL1 SDK, Metamode:Source all use it and with the exception of HL1 SDK I can't say that these projects have poo poo code.
|
# ? Nov 23, 2012 11:15 |
|
Sometimes you just need a variable to store poo poo while you're building something, what more descriptive name can you use? Is thing_tmp any better? Jewel's example of building a [complex item] to append to an existing list of [complex item]s is the most common, any name you give it is going to be equivalent to tmp or at worst very easily understandable in context.
The Gripper fucked around with this message at 11:45 on Nov 23, 2012 |
# ? Nov 23, 2012 11:42 |
|
nielsm posted:
|
# ? Nov 23, 2012 12:22 |
|
nielsm posted:
For all the times my customers ask me to implement "swap." Gordon Cole posted:sb is not nearly as bad as tmp, but it's still bad. It might not be that confusing in this particular instance, but if you ever have an abbreviated name that ends up getting used outside the immediate context of where it's declared, people aren't going to know what it is. If I just saw sb by itself I would have no idea what it means because it has no inherent meaning. In contrast I know exactly what stringBuilder means. I'll probably know what builder is too, or at the very least I'll know that it builds something.
|
# ? Nov 23, 2012 13:52 |
|
php:<? $_ ?>
|
# ? Nov 23, 2012 15:18 |
|
Someone somewhere thought this was a good idea: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Version+2+Tutorial#JIRARESTAPIVersion2Tutorial-CAPTCHAs
|
# ? Nov 23, 2012 15:26 |
|
Cocoa Crispies posted:For all the times my customers ask me to implement "swap." ...in a language that doesn't have modern assignment. code:
|
# ? Nov 23, 2012 15:32 |
|
Cocoa Crispies posted:For all the times my customers ask me to implement "swap." Some people do! Lets see what they did: glibcxx code:
|
# ? Nov 23, 2012 16:01 |
|
Cocoa Crispies posted:If your functions are taller than about ten (twenty is pushing it) lines that's the problem.
|
# ? Nov 23, 2012 16:02 |
|
Cocoa Crispies posted:For all the times my customers ask me to implement "swap." This seems like a remarkably bizarre objection.
|
# ? Nov 23, 2012 17:40 |
|
Cocoa Crispies posted:If your functions are taller than about ten (twenty is pushing it) lines that's the problem. Nah. I think it's perfectly fine to have long functions so long as the blocks within it are isolated from each other and have clear purpose. To a degree, the longer it gets, the more you're playing with fire and it can go into horror territory easily, but if you have one-time-use blocks or don't want to recalculate things it can be more straightforward than factoring out methods - until the point where the reuse that comes from making it into a method is a net positive (which IMO is a fairly low threshold to meet).
|
# ? Nov 23, 2012 17:55 |
|
Doctor w-rw-rw- posted:Complexity, readability, and maintainability don't matter people, it's all about line count! Factoring it out into a method makes you name it so the next guy has a clue what the gently caress you were thinking. Of course, now you have a different problem.
|
# ? Nov 23, 2012 18:51 |
|
If you take one-time-only code and turn it into a nullary function, all you're doing is making it hard to follow for no reason. Just put a comment for gently caress sakes.
|
# ? Nov 23, 2012 19:02 |
|
Volte posted:If you take one-time-only code and turn it into a nullary function, all you're doing is making it hard to follow for no reason. Just put a comment for gently caress sakes. One line comments are the devil and if the function is clearly named I don't need to know its inner workings to follow the code.
|
# ? Nov 23, 2012 19:13 |
|
Zombywuf posted:One line comments are the devil and if the function is clearly named I don't need to know its inner workings to follow the code. lol
|
# ? Nov 23, 2012 19:14 |
|
Good grief, I've been coding wrong all this time. Do people actually believe that if you have a function do_a_thing that might require some explaining in how it's doing a thing, it should be broken down into multiple small functions so that their names document it? At what point do you stop? That can't be more readable and maintainable than just commenting parts of interest. In a perfect world with perfect code maybe that would make sense, but why would you even be looking at the code in that case? The Gripper fucked around with this message at 19:27 on Nov 23, 2012 |
# ? Nov 23, 2012 19:23 |
|
The Gripper posted:Good grief, I've been coding wrong all this time. Do people actually believe that if you have a function do_a_thing that might require some explaining in how it's doing a thing, it should be broken down into multiple small functions so that their names document it? At what point do you stop? At the point where your functions are all less than 10 lines long obviously. quote:In a perfect world with perfect code maybe that would make sense, but why would you even be looking at the code in that case? Perhaps you should be writing more perfect code.
|
# ? Nov 23, 2012 19:32 |
|
I never believed in these line limit rules. If I make something a function, it's because I expect it to be used in more than one place.
|
# ? Nov 23, 2012 19:36 |
|
zergstain posted:I never believed in these line limit rules. If I make something a function, it's because I expect it to be used in more than one place. My guideline is that if you describe the method's purpose by saying "it does X and Y then Z", it should be 3 methods: One that does X, one that does Y, and one that does Z. The more lines of code you have, the more things it's probably doing. Following that guideline generally keeps my methods short, but I don't follow a hard-and-fast "if it's more than 10 lines, it should be two methods!" rule. [edit] And I'd consider a variable named "tmp" to be highly suspect. We live in 2012 where autocomplete is pretty much a standard IDE tool. I'd rather name a variable "swapLocation" than "tmp". I wouldn't fail it in a code review, but I'd definitely recommend giving it a more descriptive name prior to committing the code. New Yorp New Yorp fucked around with this message at 19:51 on Nov 23, 2012 |
# ? Nov 23, 2012 19:41 |
|
Ithaqua posted:My guideline is that if you describe the method's purpose by saying "it does X and Y then Z", it should be 3 methods: One that does X, one that does Y, and one that does Z. The more lines of code you have, the more things it's probably doing. People look at me weird when I say function names should not include the word "and". Sometimes they have the decency to look embarrassed though. quote:Following that guideline generally keeps my methods short, but I don't follow a hard-and-fast "if it's more than 10 lines, it should be two methods!" rule. No-one does. When I open a file and find it full of functions that don't fit in a single screen I know I'm in for a long day though.
|
# ? Nov 23, 2012 19:50 |
|
Why are we talking about phrases like "no function must be longer than X lines" as if they are strict rules across the entire spectrum of programming as a whole? Insisting a strict set of laws about writing code that hold true is as bad as having no guidelines at all. "tmp" isn't the best name, but it's not the worst name. Working on complex math problems, I often see it there because you have to give a variable some name, and there's really no purpose for what it is, outside of the fact that it's a common computation that's used in a lot of places. The purpose and meaning is nothing more than "a temporary variable". It's messy code, but complex math embedded in programming is extremely messy anyway. In a string builder context, constructing some SQL query or something? Probably not the best idea I've had, but that's the least of my worries. Any variable starting with "my" has much bigger problems.
|
# ? Nov 23, 2012 20:17 |
|
nielsm posted:
code:
|
# ? Nov 23, 2012 20:54 |
|
code:
|
# ? Nov 23, 2012 21:03 |
|
XOR swap is dangerous as hell.
|
# ? Nov 23, 2012 21:03 |
|
nielsm posted:
oldB KaneTW posted:It's hard to find any code that doesn't use 'tmp' or 'temp'. Just 'find|xargs grep' through my code folder and cURL, SQLite, LAME, Boost, Sourcemod, HL1 SDK, Metamode:Source all use it and with the exception of HL1 SDK I can't say that these projects have poo poo code. Overall they're probably not poo poo code, but any big project like those is going to have some bad parts. Just because other people use tmp doesn't mean it's good code. The Gripper posted:Sometimes you just need a variable to store poo poo while you're building something, what more descriptive name can you use? Is thing_tmp any better? Jewel's example of building a [complex item] to append to an existing list of [complex item]s is the most common, any name you give it is going to be equivalent to tmp or at worst very easily understandable in context. There is always a better name than tmp, 100% of the time. As someone pointed out, row would be good, or even better, something like tiles (assuming this is a tilemap for a game), because that describes the data that is actually in the list. Zombywuf posted:One line comments are the devil Uhhhhhhhhhh Suspicious Dish posted:"tmp" isn't the best name, but it's not the worst name. In complex math calculations that use a lot of abstract symbols, naming gets more difficult but you can still do better than tmp. Instead of c = a + tmp you can have c = a + squareRootOfB, which you can actually understand without needing to look around to find out how tmp is calculated.
|
# ? Nov 23, 2012 21:08 |
|
nielsm posted:
KaneTW posted:XOR swap is dangerous as hell.
|
# ? Nov 23, 2012 21:52 |
|
I tried it in some Galois math heavy code, unsurprisingly on modern hardware it is significantly slower than using an intermediate.
|
# ? Nov 23, 2012 22:00 |
|
Gordon Cole posted:In complex math calculations that use a lot of abstract symbols, naming gets more difficult but you can still do better than tmp. Instead of c = a + tmp you can have c = a + squareRootOfB, which you can actually understand without needing to look around to find out how tmp is calculated. Camel case is also the Devil.
|
# ? Nov 23, 2012 22:00 |
|
MrMoo posted:I tried it in some Galois math heavy code, unsurprisingly on modern hardware it is significantly slower than using an intermediate. A good compiler will optimise it out.
|
# ? Nov 23, 2012 22:00 |
|
Aleksei Vasiliev posted:d I don't think most people know about it. I only knew because I read it on a gamedev article years ago. It seems like one of those things that solves a problem you never had.
|
# ? Nov 23, 2012 22:13 |
|
Thern posted:I don't think most people know about it. I only knew because I read it on a gamedev article years ago. It seems like one of those things that solves a problem you never had. "There's no modern language that compiles to native code and isn't C++" is definitely a problem I've had before.
|
# ? Nov 23, 2012 22:18 |
|
Thern posted:I don't think most people know about it. I only knew because I read it on a gamedev article years ago. It seems like one of those things that solves a problem you never had. Was that ever a good idea? Its not like it actually saves more than one instruction, unlike some other weird looking tricks like inverse square root. Just to emphasize, heres a great example of some helpful one line comments: code:
hobbesmaster fucked around with this message at 22:29 on Nov 23, 2012 |
# ? Nov 23, 2012 22:26 |
|
hobbesmaster posted:Was that ever a good idea? Its not like it actually saves more than one instruction, unlike some other weird looking tricks like inverse square root. That seems like a great example of code that can easily be refactored to be a lot more descriptive about what the gently caress it's actually doing.
|
# ? Nov 23, 2012 22:31 |
|
|
# ? Jun 5, 2024 05:33 |
|
GrumpyDoctor posted:"There's no modern language that compiles to native code and isn't C++" is definitely a problem I've had before. I have high hopes for Rust
|
# ? Nov 23, 2012 22:38 |