Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

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.

Adbot
ADBOT LOVES YOU

mr_jim
Oct 30, 2006

OUT OF THE DARK

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.

nbv4
Aug 21, 2002

by Duchess Gummybuns

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

HFX
Nov 29, 2004

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.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Rather than arguing endlessly about the best indentation style, why don't we simply all agree on the worst- Whitesmiths:

code:
void MyFunc ()
{
while (x == y)
    {
    something();
    somethingelse();
    }
 
finalthing();
}

yippee cahier
Mar 28, 2005

just use a code reformatter and then who cares, it always looks good.

dancavallaro
Sep 10, 2006
My title sucks

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".

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
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?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Do you write x * y + z as (x * y) + z?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

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.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

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.)

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Hammerite posted:

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.

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?

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

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?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Playing it fast and loose with omitting "unnecessary" parentheses is the worst way to play code golf. Also,

code:
#!/usr/bin/perl
if ((not 0 && not 1) !=  (! 0 && ! 1)) {
  print "Larry and Tom must smoke some really primo stuff...\n";
}
For god's sake, just put the bloody parentheses in. Your parser won't mind doing the extra work and it makes the code orders of magnitude more readable.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Janin posted:

Everybody knows the precedence of + and *. Without looking at a language manual, do you know what (1 << 5 % 4 & 3) is?
If it's C, (1 << (5 % 4)) & 3.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

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.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

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?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

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.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

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.

Vanadium
Jan 8, 2005

What is everybody's favourite program/its configuration to reformat C++ code? :allears:

Zhentar
Sep 28, 2003

Brilliant Master Genius

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.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

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.

awesmoe
Nov 30, 2005

Pillbug
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

code:
int foo () 
  {
    Bob bob;
    while (1)
      {
        // stuff
        if (1)
          {
            // more stuff
          }
      }
    bob.whatsit();
  }
It was really surprising how difficult it made reading the code. Didn't help that functions were usually ~800 lines long with up to 8ish levels of nested blocks. Astonishingly, it was full of bugs!

mr_jim
Oct 30, 2006

OUT OF THE DARK

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

code:
int foo () 
  {
    Bob bob;
    while (1)
      {
        // stuff
        if (1)
          {
            // more stuff
          }
      }
    bob.whatsit();
  }
It was really surprising how difficult it made reading the code. Didn't help that functions were usually ~800 lines long with up to 8ish levels of nested blocks. Astonishingly, it was full of bugs!

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

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

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.

http://www.gnu.org/prep/standards/standards.html#Writing-C
God drat, that's one smarmy article.

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.

If you do support Windows, please do not abbreviate it as “win”. In hacker terminology, calling something a “win” is a form of praise. You're free to praise Microsoft Windows on your own if you want, but please don't do this in GNU packages. Instead of abbreviating “Windows” to “win”, you can write it in full or abbreviate it to “woe” or “w”. In GNU Emacs, for instance, we use ‘w32’ in file names of Windows-specific files, but the macro for Windows conditionals is called WINDOWSNT.

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:

printf ("size = %lu\n", (unsigned long) sizeof array);
printf ("diff = %ld\n", (long) (pointer2 - pointer1));

1989 Standard C requires this to work, and we know of only one counterexample: 64-bit programs on Microsoft Windows. We will leave it to those who want to port GNU programs to that environment to figure out how to do it.
M$$$ :supaburn:

HFX
Nov 29, 2004

Dijkstracula posted:

God drat, that's one smarmy article.


M$$$ :supaburn:

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.

awesmoe
Nov 30, 2005

Pillbug

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.

http://www.gnu.org/prep/standards/standards.html#Writing-C

Wow. I never, ever considered that anyone would institutionalize that style.

Vanadium
Jan 8, 2005

HFX posted:

code:
int c;
while ((c = getchar ()) != EOF)
   {
     unsigned char u = c;
     write (file_descriptor, &u, 1);
   }
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.

But... getchar() only ever returns values in the unsigned char range, except for when it returns EOF, so what could possibly go wrong?

HFX
Nov 29, 2004

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.

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

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?

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

awesmoe posted:

Wow. I never, ever considered that anyone would institutionalize that style.

Though anyone who uses that style should consider being institutionalized.

mr_jim
Oct 30, 2006

OUT OF THE DARK

awesmoe posted:

Wow. I never, ever considered that anyone would institutionalize that style.

This guy would.

Nomnom Cookie
Aug 30, 2009



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.

zero knowledge
Apr 27, 2008
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?

GROVER CURES HOUSE
Aug 26, 2007

Go on...
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 :negative:

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Maybe they didn't know that in Java you can do a Course [] returnCourses = new Course [numberOfCourses];

Kelson
Jan 23, 2005

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!

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?
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)

ErIog
Jul 11, 2001

:nsacloud:

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.

Adbot
ADBOT LOVES YOU

jarito
Aug 26, 2003

Biscuit Hider

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply