Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal buffer-overflowed's Journal: Grrrr.... K&R Brace style.... Not.... Valid!? 28

Ok, I'm ashamed to admit, I was helping someone(not anyone here) with their CS homework(C++).

Basic 4 function calculator type level stuff. So they send it off to me, and I go about fixing it and commenting what I changed and why. Of course in the process I cleaned up the bracing which was, well, bad. Ok, all fixed now...

Person sends it off to the professor for input. Professor responds back good yada yada but the bracing is bad.

I use K&R, apparently a heresy within the hallowed halls of podunk academia. Bastards.

Buffer smash.

This discussion has been archived. No new comments can be posted.

Grrrr.... K&R Brace style.... Not.... Valid!?

Comments Filter:
  • Which style of bracing is K&R? I'd look, but my copy is at work.
    • while (condition) {
      //stuff
      }

      int main (int argc, char *argv[]) {
      //stuff
      }

      if (something) {
      //do something
      } else {
      //do something else
      }
      • Yo, K&R braces are for fucking chumps. No shit. SUN dropped that shit like a brick for the java coding standard, and I say good-riddance.

        When you are looking at shit code with switch/case statements that go for pages or just procedures that go on for years (or worse, nested classes) having "All your ducks in a row" is a god send. (no, i don't use tools that will show you where the matching braces are, those are for sissies who don't like to debug)
        • It's a valid style, it(and Allman) are what I'm used to, and I'm so used to working via a terminal window where I need every line of vertical space I can get to see the code more than I need clear bracing it's the style I prefer.
          • Comment removed based on user account deletion
            • So do I... I find it easier to read, but that's probably just what you're used to.

              But really, saying that a "bracing-style" is wrong is just stupid. It's the content that matters, not the bracing style. Well, as long as it is readable. Putting all code in one line might piss me off too ;-)

              Isn't there a C/C++ plugin for Eclipse? Eclipse reformats Java to any style you wish. It even is fully configurable.

              • I'm just irate. I'm really irate because that's the exact bracing style that the creators of the fucking C language used in their book on the subject, so if you're going to assert that any bracing style is "wrong" while talking about programming in C/C++ it's really fsking stupid to say that one is.
                • Comment removed based on user account deletion
                  • Oddly enough, only had one like that, in the math department of one of the schools I went to. His method of playing god was to be a real ball buster. One of the few Cs I've ever gotten was in his Calc 1 class, and it's also one of the grades I'm most proud of...

                    Anyway, my CS profs wouldn't have called it bad or improper, the just would've altered the specs to include things like this.
          • I'm so used to working via a terminal window

            Buffer, we are a dying breed. Terminal window? Bah, kids these days use these fancy guis and ides to edit their so called code. Kids don't realize that screen space is is precious real-estate. They waste it with porn instead of treasuring each pixel as of their 80x24 screen for programming code. Fools. No wonder we have such bloat now in our programs, they can't even keep the bloat out of the uncomplied code, full lines for an opening brace!
            • hey, Screw You and Buffer BOTH:
              I use an IBM 3151 GREEN SCREEN. Yeah, mutherfucker, thats right. WITH VI. (none of that vim crap)

              I am HAAAD 2-D KAW.

              And ESPECIALLY when you are on a green screen, you (meaning: I) need the braces to match up.

              Dying Breed? I bet you don't even code in assembler anymore! Sucka MC. I got the shit on lock right down to the metal. (or, poly-silicon. whatever.)
        • Erm, mekkab my man, tell us how you really feel will ya? :)

          Besides, how is K&R (in buffer-overflowed's example) different from The Java coding standards [sun.com]?

          Yes, switch statements are unnecessary and I have grown to like the Java naming convention [sun.com] (forgot the name of the caps one) versus the underscore convention.

          Did I miss your point somehow? be gentle ;)
      • is for braces one separate lines. But to call this style "bad" is just the sign of a bozo.
      • My boyfriend writes his code that way. I drive him crazy. I prefer:

        while (condition)
        {
        //stuff
        }

        int main (int argc, char *argv[])
        {
        //stuff
        }

        if (something)
        {
        //do something
        }

        else
        {
        //do something else
        }

        Of course, I am just now getting around to learning to code. Before this year, I was purely an assembly person. My code ends up pages and pages long, but it certainly helps to keep me straight while I am learning.
        • That's perfectly alright. The most important thing imo is consistancy within a program. Otherwise it gets confusing around debug time.

        • One option to working with other folk's code: indent.

          gnu indent [gnu.org]

          It will format format the code quite nicely and you have a number of options, one being the k&r style or the style you have above. Other options are how many spaces for indent (or tabs).

          If you have to work with java code, jalopy [sourceforge.net] is an excellent program for formatting. It can choke up on java docs though, so be careful with html tags in javadocs.
        • Yes, this is called Whitesmiths style, and it is what I use.
      • That's what I use, except I indent 3 spaces instead of 2.

        -Ab

        • GGGRRRR!

          3, wtf three spaces? What unnatural programming style. God meant for us to use tabs for a reason, you can control what a tab is with your editor (3 spaces if you like, or 8 like a normal human, or 4 if you are new age). My boss uses 3 spaces (and hence our programming style for our company), it drives me nuts! What is the logic of three spaces? And odd number?!?
          • What is the logic of three spaces?

            It's like a machine gun in burst mode. You have single-shot, burst (3), or full auto. It comes from programmer's latent agression.

            The above is completely balderdash.
            • Hmmm... I think I need to get me one of them machine guns. I have a perfect target for the first burst then. ;-) No more three spaces after that.
      • Comment removed based on user account deletion

The difference between reality and unreality is that reality has so little to recommend it. -- Allan Sherman

Working...