|
Zhentar posted:1TBS is accurately named. I actually consistently type code in 1TBS, and let VS turn it into Allman style. The visual change helps me balance braces.
|
# ? Mar 27, 2010 04:36 |
|
|
# ? Apr 27, 2024 09:11 |
|
Ryouga Inverse posted:I actually consistently type code in 1TBS, and let VS turn it into Allman style. The visual change helps me balance braces. I turn on 'showmatch' in Vim for that. If it's up to me, I use 1TBS. If I'm working on existing code, I'll use whatever style is already being used. Unless it's GNU style. That poo poo sucks.
|
# ? Mar 27, 2010 04:58 |
|
1337JiveTurkey posted:it turns out that a comment block immediately after an if or an else statement acts in exactly the manner that ColdPie's describing. same goes for javascript
|
# ? Mar 27, 2010 05:14 |
|
nbv4 posted:same goes for javascript I'll have to remember to look out for that in coworkers javascript code. I use 1TBS for almost all of my code.
|
# ? Mar 27, 2010 12:40 |
|
Rather than arguing endlessly about the best indentation style, why don't we simply all agree on the worst- Whitesmiths:code:
|
# ? Mar 27, 2010 13:25 |
|
just use a code reformatter and then who cares, it always looks good.
|
# ? Mar 27, 2010 18:11 |
|
sund posted:just use a code reformatter and then who cares, it always looks good. You do realize that a code reformatter reformats code to a specified style, right? It doesn't just magically make your code "look good", for some undefined value of "good".
|
# ? Mar 27, 2010 18:22 |
|
Using an if block, for block, or whatever and omitting the braces is just bad in my opinion. It's like omitting brackets just because you know what the order of operations is; why make things less clear for the reader?
|
# ? Mar 27, 2010 19:31 |
|
Do you write x * y + z as (x * y) + z?
|
# ? Mar 27, 2010 20:01 |
|
Hammerite posted:Using an if block, for block, or whatever and omitting the braces is just bad in my opinion. It's like omitting brackets just because you know what the order of operations is; why make things less clear for the reader? Whooooooooo caaaaaaaaaares
|
# ? Mar 27, 2010 20:11 |
|
Plorkyeran posted:Do you write x * y + z as (x * y) + z? No. Although I would not object to seeing it. I think BODMAS (or whatever you learnt it as) is sufficiently basic to be assumed. Obviously some base level of knowledge could be assumed in all instances. But I would stop short or writing, I don't know, x and y or a and b when I could write (x and y) or (a and b), because buggered if I can remember whether and or or has higher precedence.
|
# ? Mar 27, 2010 20:12 |
|
Plorkyeran posted:Do you write x * y + z as (x * y) + z? No, but that's maths and 'multiplication's done before addition' is a much better known rule than 'AND's done before OR'. (And yes, I had to look that one up to check.)
|
# ? Mar 27, 2010 20:14 |
|
Hammerite posted:No. Although I would not object to seeing it. So in other words, you support leaving out the parentheses when you know the order of operations but want them there when you don't?
|
# ? Mar 27, 2010 20:23 |
|
Plorkyeran posted:So in other words, you support leaving out the parentheses when you know the order of operations but want them there when you don't? Everybody knows the precedence of + and *. Without looking at a language manual, do you know what (1 << 5 % 4 & 3) is?
|
# ? Mar 27, 2010 20:27 |
|
Playing it fast and loose with omitting "unnecessary" parentheses is the worst way to play code golf. Also,code:
|
# ? Mar 27, 2010 20:30 |
|
Janin posted:Everybody knows the precedence of + and *. Without looking at a language manual, do you know what (1 << 5 % 4 & 3) is?
|
# ? Mar 27, 2010 20:31 |
|
Plorkyeran posted:So in other words, you support leaving out the parentheses when you know the order of operations but want them there when you don't? Yep, fairly close to that. But I'd certainly be charitable enough to put them in when I don't feel it's sufficiently "common knowledge" what the order of operations is.
|
# ? Mar 27, 2010 20:33 |
|
Hammerite posted:Yep, fairly close to that. But I'd certainly be charitable enough to put them in when I don't feel it's sufficiently "common knowledge" what the order of operations is. So what does this have to do with leaving the braces out of an if block?
|
# ? Mar 27, 2010 20:46 |
|
HappyHippo posted:So what does this have to do with leaving the braces out of an if block? Nothing instrinsically. They are two separate things that I consider to be bad ideas on the grounds of contributing to poor understandability.
|
# ? Mar 27, 2010 21:03 |
|
nbv4 posted:same goes for javascript what interpreter? I just tried safari, firefox, ie and opera and none of them allowed the comment to interrupt "normal" parsing.
|
# ? Mar 27, 2010 22:25 |
|
What is everybody's favourite program/its configuration to reformat C++ code?
|
# ? Mar 27, 2010 23:04 |
|
Hammerite posted:I think BODMAS (or whatever you learnt it as) is sufficiently basic to be assumed. Obviously some base level of knowledge could be assumed in all instances. I find it easier to just always use parenthesis rather than try to keep track of whether or not whatever I'm using today actually correctly follows order of operations.
|
# ? Mar 27, 2010 23:31 |
|
Zhentar posted:I find it easier to just always use parenthesis rather than try to keep track of whether or not whatever I'm using today actually correctly follows order of operations. Yes but you're the only one in this thread who uses MUMPS.
|
# ? Mar 27, 2010 23:52 |
|
Normally I'm happy to use whatever brace style is in the file I'm working on, but I recently had to maintain some code that uses thiscode:
|
# ? Mar 28, 2010 00:09 |
|
awesmoe posted:Normally I'm happy to use whatever brace style is in the file I'm working on, but I recently had to maintain some code that uses this Welcome to GNU-style indenting. Usually the opening brace of a function definition isn't indented though. And they put the return type of the function on it's own line. http://www.gnu.org/prep/standards/standards.html#Writing-C
|
# ? Mar 28, 2010 00:17 |
|
mr_jim posted:Welcome to GNU-style indenting. Usually the opening brace of a function definition isn't indented though. And they put the return type of the function on it's own line. quote:As for systems that are not like Unix, such as MSDOS, Windows, VMS, MVS, and older Macintosh systems, supporting them is often a lot of work. When that is the case, it is better to spend your time adding features that will be useful on GNU and GNU/Linux, rather than on supporting other incompatible systems. quote:Similarly, don't make any effort to cater to the possibility that long will be smaller than predefined types like size_t. For example, the following code is ok:
|
# ? Mar 28, 2010 00:25 |
|
Dijkstracula posted:God drat, that's one smarmy article. It has some good points, honestly. I did find something I didn't like: [code] int c; while ((c = getchar ()) != EOF) { unsigned char u = c; write (file_descriptor, &u, 1); } [code] Yes an actual recommendation to coerce to a smaller type without an explicit cast. I know C lets you. It usually is not a good idea.
|
# ? Mar 28, 2010 00:44 |
|
mr_jim posted:Welcome to GNU-style indenting. Usually the opening brace of a function definition isn't indented though. And they put the return type of the function on it's own line. Wow. I never, ever considered that anyone would institutionalize that style.
|
# ? Mar 28, 2010 00:44 |
|
HFX posted:
But... getchar() only ever returns values in the unsigned char range, except for when it returns EOF, so what could possibly go wrong?
|
# ? Mar 28, 2010 00:47 |
|
Vanadium posted:But... getchar() only ever returns values in the unsigned char range, except for when it returns EOF, so what could possibly go wrong? In this case, likely nothing. However, I wouldn't want to rely on that always. I'd much rather see the explicit cast to mean that is what you really want to do.
|
# ? Mar 28, 2010 01:04 |
|
Internet Janitor posted:Rather than arguing endlessly about the best indentation style, why don't we simply all agree on the worst- Whitesmiths: I'm working on a medium-sized C++ project that's inherited a lot of Whitesmiths formatted code as a legacy. We've decided that we want to change that for consistency reasons though (due to the size of the code, preferably automated). I've been told GNU indent doesn't work too well with C++ code. Do you have any experience with code reformatters, and if so, which one would you recommend?
|
# ? Mar 28, 2010 02:42 |
|
awesmoe posted:Wow. I never, ever considered that anyone would institutionalize that style. Though anyone who uses that style should consider being institutionalized.
|
# ? Mar 28, 2010 02:44 |
|
awesmoe posted:Wow. I never, ever considered that anyone would institutionalize that style. This guy would.
|
# ? Mar 28, 2010 02:56 |
|
If you put five programmers together, no two of them will agree on what the best brace style is...but all of them will agree that GNU style is the worst.
|
# ? Mar 28, 2010 05:20 |
|
A coding horror: I found myself working on a medium scale Java project at university. I know school projects and assignments are cheap shots when it comes to coding horrors, but this is a higher level class so I'd expect some measure of competence at this stage. I was working on a calendar component of a course management tool (think WebCT or Blackboard but not lovely... except of course it turned out to be even shittier than WebCT). Some other guys were responsible for the database stuff. I decided to let them do whatever awful poo poo they felt necessary since it'd be easier to deal with the consequences later than to argue about it--it's a disposable school project in an awful class so who gives the merest shadow of a poo poo about how good it actually is. One particular database API I need to use is Courses[] getCoursesByUserID(int userID). I'm iterating over the array it returns to create the appropriate number of tabs in the UI and find I'm getting NullPointerExceptions. Well, maybe the particular user has no courses and the array is null (as it should be in such a case). I add a check against this and still get an NPE. Well what the gently caress? So it turns out that in the method that grabs the courses from the DB, we have the following: Course [] returnCourses = new Course [10]; ... /* DB query result copied into returnCourses */ ... If the user has fewer than 10 courses? Get hosed, eat some null pointers. User has more than 10 courses? Holy gently caress I hope that doesn't happen! I've heard the adage that everyone has 10,000 lines of poo poo code in them they need to get out. I get that I'm working with students. Certainly I've written some awful stinkers in my time. But these are third and mostly fourth year computer or software engineering students. Is this kind of thing really beyond them?
|
# ? Mar 28, 2010 08:45 |
|
The only possible excuse is that it's debug code that somehow snuck into the final thing, but that only diminishes it from a crime against computer science to an atrocity of a slightly milder sort. This is what they teach you in the first month of CS, why would you even
|
# ? Mar 28, 2010 08:59 |
|
Maybe they didn't know that in Java you can do a Course [] returnCourses = new Course [numberOfCourses];
|
# ? Mar 28, 2010 09:44 |
|
Spazmo posted:If the user has fewer than 10 courses? Get hosed, eat some null pointers. User has more than 10 courses? Holy gently caress I hope that doesn't happen!
|
# ? Mar 28, 2010 10:55 |
|
Kelson posted:If you think 3-4 year CS students should know better, I've worked with grad degree holding folks who submit similar garbage. Global constants everywhere, smoke-and-mirror gotos, type abuse, unsafe code (or the ever popular 'catch any error, ignore, continue execution normally'), and memory leaks everywhere (Java will normally catch that - but not if you keep the old data in your data structures... forever) To expand on this, if there can be coding horrors in applications that are products that companies sell then certainly there are going to be coding horrors in applications where the stakes are far lower, like student projects.
|
# ? Mar 28, 2010 16:57 |
|
|
# ? Apr 27, 2024 09:11 |
|
Wheany posted:Maybe they didn't know that in Java you can do a Course [] returnCourses = new Course [numberOfCourses]; Or just use a higher level construct like a List, Hash or Set.
|
# ? Mar 29, 2010 18:06 |