The 1 true style

Please compose all posts in Emacs.

Moderators: phlip, Prelates, Moderators General

Re: The 1 true style

Postby Vempele » Mon Mar 23, 2009 9:30 pm UTC

Berengal wrote:
Vempele's sig wrote:auto fib = series!("a[n-1] + a[n]")(1, 1);

Emphasis mine.

Special case: numbers. 1,1 in Finland == 1.1 nearly everywhere else. Also note it's just two arguments rather than five.
const int ALMOST_FIFTY = 80;
Vempele
 
Posts: 69
Joined: Wed Nov 14, 2007 8:05 am UTC

Re: The 1 true style

Postby Berengal » Mon Mar 23, 2009 10:38 pm UTC

Finland != programming language.

Five-argument functions have even more reason to put spaces inbetween their arguments, possibly even newlines. If the arguments are all single-letter variables then no amount of formatting would help. Actually, a five-argument function is horrible enough without considering how the arguments are laid out anyway.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: The 1 true style

Postby stephentyrone » Mon Mar 23, 2009 11:00 pm UTC

Berengal wrote:Actually, a five-argument function is horrible enough without considering how the arguments are laid out anyway.


Heh...

Code: Select all
int zgtsvx_(char *fact, char *trans, long *n, long *nrhs, complex double *dl, complex double *d__, complex double *du, complex double *dlf, complex double *df, complex double *duf, complex double *du2, long *ipiv, complex double *b, long *ldb, complex double *x, long *ldx, double *rcond, double *ferr, double *berr, complex double *work, double *rwork, long *info);
GENERATION -16 + 31i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.
stephentyrone
 
Posts: 779
Joined: Mon Aug 11, 2008 10:58 pm UTC
Location: Palo Alto, CA

Re: The 1 true style

Postby Xanthir » Tue Mar 24, 2009 1:57 am UTC

Honestly, is there any reason besides inertia that we put commas in at all? I mean, we don't allow whitespace within variable names, and only allow it within explicit values in special circumstances (like if it's surrounded by quotes). A lot of things would be simpler if we just used space-delimited lists for everything.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: The 1 true style

Postby phlip » Tue Mar 24, 2009 2:34 am UTC

Well, infix notation, for one. There are more things that can be used as actual parameters besides variable names and quoted literals... and some of those can have spaces in them. Sure, in many languages some of them can have commas in them too, but the comma operator is rarely enough used to not worry about it. Sure, pretty much any expression in C can be written without use of spaces, but having them there can significantly help readability.

Sure, it'd be nice if all languages used LISP-style syntax, but they don't.
While no one overhear you quickly tell me not cow cow.
but how about watch phone?
User avatar
phlip
Restorer of Worlds
 
Posts: 7140
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia

Re: The 1 true style

Postby 0xBADFEED » Tue Mar 24, 2009 3:06 am UTC

phlip wrote:Well, infix notation, for one. There are more things that can be used as actual parameters besides variable names and quoted literals... and some of those can have spaces in them... <snip>

I think Xanthir was probably planning on using parentheses to fix these problems.
So..
Code: Select all
func(x, y + z)  ->  func(x (y + z))  or  ->  func x (y + z)

Personally, I like the comma syntax in function application (at least in C-style languages) and list/tuple-building. It seems more natural to me as it's the syntax used to represent series in both English and many mathematical contexts. In functional languages I do prefer the comma-less function application syntax.
0xBADFEED
 
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: The 1 true style

Postby phlip » Tue Mar 24, 2009 3:16 am UTC

Actually, now that you put it like that, it looks a lot like Logo...
While no one overhear you quickly tell me not cow cow.
but how about watch phone?
User avatar
phlip
Restorer of Worlds
 
Posts: 7140
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia

Re: The 1 true style

Postby Xanthir » Tue Mar 24, 2009 12:56 pm UTC

Actually, I just completely blanked on the fact that you can pass complete expressions as an argument in an ambiguous way in most languages. It's *so* not an issue in Lisp it didn't occur to me that it would be elsewhere...

That said, parens ftw.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: The 1 true style

Postby Berengal » Tue Mar 24, 2009 2:13 pm UTC

Xanthir wrote:That said, parens ftw.

commas parens or rpn or solution.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: The 1 true style

Postby Ptolom » Tue Apr 07, 2009 8:33 pm UTC

I just layout my code the way I feel like at the time. Ive never had a problem yet, though that's probably because I never write anything more than about 300 lines long. I used to be worse. Once (I was only 12 I didn't know any better) I wrote a game in BBC BASIC that was just 1000 lines of hideous, entirely uncommented spaghetti code. I didn't use anything but GOTO then. Luckily it was lost when my hard drive died so I've spared the shame of reading it.
It Should Be Real wrote:Fuck the wizard.
We're doing this manually.

http://www.hexifact.co.uk - Hacking blog: in which I take some things apart, and put other things together.
User avatar
Ptolom
 
Posts: 1543
Joined: Mon Mar 24, 2008 1:55 pm UTC
Location: The entropy pool

Re: The 1 true style

Postby TjOeNeR » Wed Apr 08, 2009 12:06 pm UTC

I prefer Allman style, but for long function definitions, or long conditional statements, I tend to split the code up into seperate lines.

This because I use my IDE (Visual Studio, I'm a C# guy what do you want), in a pretty weird config when I'm debugging.
Locals on the right, output next to call stack in the bottom, and solution explorer to the left. On a 1680 screen with Courier New set a tad smaller than default (gotta love ClearType) I get about 100 columns. So overly long lines do get cut.

I like to use a lot of white space too. 3 lines between functions, and liberally sprinkled single lines in a function. Also no tabs, tabs set to overly large sizes (like 8, I mean WTF) in some editors make the code very unreadable and very indented very fast. This off course because of C#'s way of writing files.

Code: Select all
namespace MyNamespace
{
    class MyClass
    {
        public function DoSomething(string someString)
        {
/*12spaces!*/
             Console.Writeline(someString);
        }
    }
}
TjOeNeR
 
Posts: 16
Joined: Sun Oct 19, 2008 6:30 pm UTC
Location: Antwerp - Belgium

Re: The 1 true style

Postby chaosspawn » Fri Apr 10, 2009 3:48 pm UTC

Man indenting, who needs that.
Code: Select all
MOVF   f,W ;arbitrary commands
XORWF  f
DECFSZ f,W
GOTO X
INCF   f

That being said, even as an EE I find more occasion to use C nowadays than straight up assembler. When doing that I'm a fan of Allman (brothers).
I still have some stupid affection for the Decrement Skip if Zero command though, and I've never whined about any if statements being hard to follow after learning that was what I got to work with in assembler.

Also on tabs, I really prefer that my editor is always set to the "use spaces for tab" mode, that way there's no actual tab characters in any of my files. Possibly inconvenient, but most IDEs have a "pretty-ify" button that can fix up the style if someone really needs a different indenting scheme.
This space intentionally left blank.
User avatar
chaosspawn
 
Posts: 560
Joined: Thu Aug 09, 2007 6:38 pm UTC
Location: Waltham, MA

Re: The 1 true style

Postby stephentyrone » Fri Apr 10, 2009 4:43 pm UTC

chaosspawn wrote:Man indenting, who needs that.
Code: Select all
MOVF   f,W ;arbitrary commands
XORWF  f
DECFSZ f,W
GOTO X
INCF   f



You say "indenting, who needs that", and then you have your register names nicely indented to line up. O.o
GENERATION -16 + 31i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.
stephentyrone
 
Posts: 779
Joined: Mon Aug 11, 2008 10:58 pm UTC
Location: Palo Alto, CA

Re: The 1 true style

Postby stolid » Sun Apr 12, 2009 12:06 am UTC

I do the style where braces line up too. Its harder to forget them/not notice them/etc that way. Everyone seems to line up the very first and last brace in a program, so why not indent and do the same for each further embedded block?
Registered Linux User #555399
stolid
 
Posts: 167
Joined: Mon Sep 15, 2008 3:18 am UTC
Location: 25th state

Re: The 1 true style

Postby zombiefeynman » Sun Apr 12, 2009 5:15 pm UTC

I used to write in I style I'd gotten used to in eclipse:

(These tabs should be 4 spaces by the way)
Code: Select all
int q, g, f=0, u=7;
void do_something(int a, int b, bool c){
   if ((a+b)>9){
      do_something_else(c);
   } else {
      do_something_else(a==b);
   }
   while(c){
      do_another(c);
   }
}


Then I realized I was coding in ... java style! So I quickly converted to K&R, because they are two respectable gentlemen and I can still see what I'm doing when I scrunch my IDE up real small.

If I use anything else - especially one of those styles that says you should give brackets their own line - I end up scrolling up and down far too much.
User avatar
zombiefeynman
 
Posts: 211
Joined: Thu Apr 02, 2009 4:16 pm UTC

Re: The 1 true style

Postby Comic JK » Fri Apr 24, 2009 5:13 pm UTC

My preferred style is a modified Allman, like so:
Code: Select all
int functionName()
{
    while(conditional)
    {
          //large block of code
          ...
          //is well-defined
    }
    if(shortConditional) shortStatement; //Save lines and read more easily
    if(somewhatLongerConditionalIsToLongForOneLine)
          { multiple(); short(); statements(); } //My personal favorite
}

As usual, it's fine if you disagree; you'll find out the truth when the Great Cleansing comes.
Image
A webcomic funnier than life itself. Updated Monday-Friday.
Comic JK
 
Posts: 271
Joined: Wed Feb 18, 2009 6:08 pm UTC

Re: The 1 true style

Postby MHD » Thu Apr 30, 2009 8:54 pm UTC

Code: Select all
function someFunc(int arg1,int arg2) { if (arg1) {arg2++; return arg2;} elseif (arg2) {arg1++; return arg1;} else {arg1++; arg2++;}}


Oneliners is the only way
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"
User avatar
MHD
 
Posts: 631
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: The 1 true style

Postby You, sir, name? » Fri May 08, 2009 10:56 pm UTC

This is how I be coding, and it is the one true way.

Code: Select all
void main(int argc, char* argv[]) {
    int variable = get_a_value();

    if(variable == SOME_VALUE) do_foo();
    else if(variable == SOME_OTHER_VALUE)
        do_a_longer_command();
    else if(variable == SOME_OTHER_VALUE-1 &&
              another_condition() == TRUE)
        do_something();
    else if(variable == SOME_OTHER_VALUE-2 &&
              another_condition() == TRUE) {
        do_yet_another_command();
        and_something_else++;
    } else {
       do_bar();
       do_something_else();
    }
    return EXIT_SUCCESS;
}
I now occasionally update my rarely-updated blog.

I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.
User avatar
You, sir, name?
 
Posts: 6493
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: The 1 true style

Postby Ran4 » Tue Jun 30, 2009 11:18 pm UTC

Spoiler:
Code: Select all
int main(int argc, char *argv[])
{
   int a, b, c;
   int d = 50, e = 40;
   
   if (b)
      doB();
   
   if (d > e)
   {
      doSomething();
   }
   else if (a)
   {
      cout << "E is bigger.";
      doSomethingElse();
   }
   else
   {
      cout << "E and D are equal";
      doSomeThirdThing();
   }

    if (e > d || d > e ||
         (e == d && 1==1))
      cout << "Hello";
   
   return 0;
}

That's the way to do it. Allman style. With tabs. Like above.
I'm more interest in where the comments go. I love inline commenting, something that some people seems hate.
User avatar
Ran4
 
Posts: 131
Joined: Mon May 04, 2009 2:21 pm UTC

Re: The 1 true style

Postby JordyD » Fri Aug 14, 2009 8:46 pm UTC

Hammer wrote:For myself, I like Allman. However, my main requirement for style is that, whatever you decide to do, do it consistently! I regularly get handed code from beginners whose reaction to suggestions to maintain a consistent style is "Do I haaaaave to?" Then, after listening to them whine, I get to plow through code that uses three different indenting styles selected at random when they bother to indent at all. Grrrrrrrrr...


GNU Indent?

Anyways, this is my style:
Spoiler:
Code: Select all
#include "aclass.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
        for (int i = 0; i < 10; i++)
                cout << i << endl;

        if (true)
        {
                doStuff();
                doMoreStuff();
        }

        if (THERE_IS_THIS_REALLY_LONG_MACRO ||
              I_NEED_TO_MAKE_MULTIPLE_LINES)
                doStuff();

        string aString = "This is how variables are named.";
        cout << aString << " And if I have multi-line streams, it goes "
             << "like this." << endl;

        AClass aClass;
        aClass.SetText("This is generally how classes and their methods are named.");

        return 0;
}


I usually change my naming conventions to those of the library I'm using, for consistency.
JordyD
 
Posts: 2
Joined: Fri Jun 12, 2009 2:56 am UTC

Re: The 1 true style

Postby cerbie » Sun Aug 16, 2009 8:02 pm UTC

One of my favorite quips about the issue: You know you're brilliant, but maybe you'd like to understand what you did 2 weeks from now.

I like K&R/Java/One True Brace. I don't care one way or another if functions get an extra line for a brace or not.
Real tabs for indenting. I have been in the habit, for quite some time, of using the left and right keys to navigate indentation levels.
Spaces added to align things on new lines, with operators to begin the line.
Spoiler:
Code: Select all
if ( longstuffgoeshere...
     || morestuff ) {
        stuffinblock // assume this is from an 8-space tab setting
}
This way, there is a more obvious cue that it is not a new statement.

For more wordy languages, like VB, SQL (ew on both counts), Ruby, and so on, I throw in an extra indent for a function/routine's begin (if any), body, and end, since there aren't always easily recognizable symbols for the job. FI, some Lua, currently open:
Spoiler:
Code: Select all
tobase10 = function (t)
      local r, fstring = '', formatstring[ t.size ]
      if t[ #t ] == 0 then
         return '0'
      else
         for i,v in ipairs( t ) do
            r = fstring:format( v ) .. r
         end
         r = r:gsub('^0*','' )

         if t.sign == -1 then
            r = '-' .. r
         end
         return r
      end
   end
Without nice little symbols, like braces, I find prefixing the end word with a tab to aid in skimmability, rather than lining it up with the next statement below it.
DSenette: (...) on the whole, even a trained killer cow is kind of stupid.
User avatar
cerbie
 
Posts: 934
Joined: Sat Jul 05, 2008 5:14 am UTC
Location: USA

Re: The 1 true style

Postby Ptolom » Sun Aug 16, 2009 9:33 pm UTC

Ok, ok, I've given in and dropped into using Allman.
It Should Be Real wrote:Fuck the wizard.
We're doing this manually.

http://www.hexifact.co.uk - Hacking blog: in which I take some things apart, and put other things together.
User avatar
Ptolom
 
Posts: 1543
Joined: Mon Mar 24, 2008 1:55 pm UTC
Location: The entropy pool

Re: The 1 true style

Postby tommorris » Wed Apr 28, 2010 10:33 pm UTC

blob wrote:
Karrion wrote:Agreed. However I would make one strong recommendation on that style: Please, please get out of the habit of omiting braces for single statement conditionals/loops. It's only a couple more keystrokes, but will save you a lot of time later trying to work out why that line you just added to a loop isn't being executed...

Which is why Python wins at syntax. Humans persistently believe that indentation has meaning, despite the fact that C/C++/Java compilers will happily throw bugs at you to prove that it doesn't. Python turns that around and says, if people think it should have meaning, why not make it so?


As is proved every time you go to a Python blog and read the comments and the crappy blog software pulls out all the spacing and indentation. Really is great fun that. Yet, somehow, the Python programmers still manage to work out what it means despite all the precious indentation disappearing off to the bit bucket. :mrgreen:
tommorris
 
Posts: 11
Joined: Wed Apr 28, 2010 9:45 pm UTC

Re: The 1 true style

Postby stolid » Tue Aug 31, 2010 3:01 am UTC

I like Allman style as well. I like the braces being lined up. It really annoys me when an opening (and closing) brace isn't on its own line. It seems messy to me in those instances.
Registered Linux User #555399
stolid
 
Posts: 167
Joined: Mon Sep 15, 2008 3:18 am UTC
Location: 25th state

Re: The 1 true style

Postby Thesh » Sat Sep 11, 2010 4:43 am UTC

I prefer this style

Code: Select all
      
         function a(int j) {
      int i;
      for (i=0;i<j;i++) {
   if (i==j) {
//something
   }
   else {
//somethingelse
   }
      }
         }


I do like allman, and use it for C#. For C, C++, and Javascript I tend to use K&R (with the exception that I don't have a newline before the function brace) just because that is the style I learned when I started with C.
Big are getting bigger and hearts are getting harder, an imaginary game
eating at every living thing, a voice dripping with sarcasm like a bloody fat slash
grinning over bleached white-fang teeth that glow like green warning signs of sickness.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 3576
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: California, Southern USA

Re: The 1 true style

Postby spupy » Thu Jan 20, 2011 12:53 am UTC

I use the Ctrl+Shirt+F style, because it is the style to which Eclipse formats when I press that key combo.
I have no idea to which real style it corresponds to. Ideas?

EDIT: After checking Wikipedia, it looks like 1TBS - "The One True Brace Style".
There are two types of people in this world - those who can count to 10 by using their fingers, and those who can count to 1023 by using their fingers.
spupy
 
Posts: 154
Joined: Sun Apr 13, 2008 10:48 pm UTC

Re: The 1 true style

Postby flying sheep » Thu Jan 20, 2011 1:32 am UTC

tommorris wrote:As is proved every time you go to a Python blog and read the comments and the crappy blog software pulls out all the spacing and indentation. Really is great fun that. Yet, somehow, the Python programmers still manage to work out what it means despite all the precious indentation disappearing off to the bit bucket. :mrgreen:
you sound like this was python’s fault.
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: The 1 true style

Postby Darryl » Sat Jan 22, 2011 10:50 pm UTC

On the original topic, back when I was taking programming courses (before I decided I'd rather be a math teacher than a code monkey), I used Allman, with tabs, not spaces. Because I was weird, and liked my 3-space tabs, while most of my classmates kept their tabs at the environment's default.

I definitely found Allman the most readable (and being the default style my professors used helped that a bit, too).
yurell wrote:We need fewer homoeopaths, that way they'll be more potent!
Darryl
 
Posts: 327
Joined: Mon Sep 22, 2008 2:32 pm UTC

Re: The 1 true style

Postby huangho » Mon Feb 07, 2011 2:19 am UTC

I mostly follow K&R, except that I put the opening brace of a function in the same line as the parameter list. K&R's putting the brace in a separate line made sense when you had to declare the parameter types between the parameter list and the opening brace, but in modern C it is just an inconsistency.

About Lisp: everyone knows that the proper way of indenting an if form is:
Code: Select all
(if (> x 42)
    (then-clause)
  (else-clause))
huangho
 
Posts: 9
Joined: Sat Sep 25, 2010 12:43 am UTC

Re: The 1 true style

Postby flying sheep » Mon Feb 07, 2011 7:32 pm UTC

huangho wrote:
Code: Select all
(if (> x 42)
    (then-clause)
  (else-clause))

any reasoning backing this one?
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: The 1 true style

Postby Yakk » Mon Feb 07, 2011 7:44 pm UTC

flying sheep wrote:
tommorris wrote:As is proved every time you go to a Python blog and read the comments and the crappy blog software pulls out all the spacing and indentation. Really is great fun that. Yet, somehow, the Python programmers still manage to work out what it means despite all the precious indentation disappearing off to the bit bucket. :mrgreen:
you sound like this was python’s fault.

It is python's fault. The problem of "whitespace is eaten by various tools" was a known problem prior to Python being released.

Python said "that's ok, I don't mind if the compileability of the code is fragile. I have principles."
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.
User avatar
Yakk
Poster with most posts but no title.
 
Posts: 10370
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: The 1 true style

Postby flying sheep » Mon Feb 07, 2011 9:04 pm UTC

Yakk wrote:
flying sheep wrote:
tommorris wrote:As is proved every time you go to a Python blog and read the comments and the crappy blog software pulls out all the spacing and indentation. Really is great fun that. Yet, somehow, the Python programmers still manage to work out what it means despite all the precious indentation disappearing off to the bit bucket. :mrgreen:
you sound like this was python’s fault.

It is python's fault. The problem of "whitespace is eaten by various tools" was a known problem prior to Python being released.

Python said "that's ok, I don't mind if the compileability of the code is fragile. I have principles."

nah, guido rather said “don’t fucking post code into crappy content management systems, or it’ll look like they had anything to do with us.”

and magically, every content management system written in python has a method to paste code without eating the whitespace and thus is less crappy.

mission accomplished!
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: The 1 true style

Postby flying sheep » Mon Feb 07, 2011 9:12 pm UTC

it’s the same principle as with editors/ides which can’t visualize different kinds of whitespace. they obviously can’t handle code, so go bug the developers, or get active yourself, if you want your crappy editor of choice to be useable.

not python’s fault. i can happily use tab-indentation with space-alignment*, because my editor doesn’t suck, so i instantly see if i have misplaced a whitespace character.

*until elastic tabstobs are widely accepted. also, i seldom have to align much.
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: The 1 true style

Postby Yakk » Mon Feb 07, 2011 10:44 pm UTC

Thanks for illustrating why it is Python's fault? Python would rather break than be impure.

It is a choice. The other choice is to be robust even in the face of other people's failure. Python didn't choose that, so Python is fragile. Python choosing to be fragile is Python's fault.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.
User avatar
Yakk
Poster with most posts but no title.
 
Posts: 10370
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: The 1 true style

Postby Xanthir » Tue Feb 08, 2011 2:12 am UTC

huangho wrote:About Lisp: everyone knows that the proper way of indenting an if form is:
Code: Select all
(if (> x 42)
    (then-clause)
  (else-clause))

Um, what? No, the proper way to indent an IF form is "whatever PRETTY-PRINT spits out", because Lisp has an official pretty-printer.

Usually that means you'll get
Code: Select all
(if (> x 42)
    (then-clause)
    (else-clause))


But if the expression is short enough, and it's not already indented too far, it'll just be
Code: Select all
(if (> x 42) (then-clause) (else-clause))


If you're indenting Lisp code manually, you're doing it wrong.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: The 1 true style

Postby huangho » Tue Feb 08, 2011 4:47 am UTC

Xanthir wrote:If you're indenting Lisp code manually, you're doing it wrong.

Actually, the indenting style I use is what Emacs does by default. I find it far more legible than putting the then-clause and the else-clause at the same level. (I actually don't use Emacs, though.)
huangho
 
Posts: 9
Joined: Sat Sep 25, 2010 12:43 am UTC

Re: The 1 true style

Postby Xanthir » Tue Feb 08, 2011 6:08 pm UTC

I reiterate my statement. If you're indenting in any way other than what PRETTY-PRINT does, you're doing it wrong.

I write my code using whatever default indentation my editor gives me. Then I highlight the block, right click, and select "Pretty Print" before saving.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: The 1 true style

Postby huangho » Tue Feb 08, 2011 7:30 pm UTC

Xanthir wrote:I write my code using whatever default indentation my editor gives me. Then I highlight the block, right click, and select "Pretty Print" before saving.

Right-click? You're telling me you edit code with a mouse? :shock:

Seriously, I don't see why having the editor indent it automatically the way you want is more manual than using the pretty-printer to do it. I would indeed be doing less manual work by letting the editor do it. (I'm arguing just to understand the reasoning behind this; I actually do it wrong and indent my ifs and unwind-protects manually to match Emacs' standard. I have been thinking about switching to Emacs lately, but still haven't done so.)
huangho
 
Posts: 9
Joined: Sat Sep 25, 2010 12:43 am UTC

Re: The 1 true style

Postby Xanthir » Wed Feb 09, 2011 6:52 am UTC

huangho wrote:
Xanthir wrote:I write my code using whatever default indentation my editor gives me. Then I highlight the block, right click, and select "Pretty Print" before saving.

Right-click? You're telling me you edit code with a mouse? :shock:

You kids and your old-fangled console editors. When I was young I used a GUI, and I liked it!

Seriously, I don't see why having the editor indent it automatically the way you want is more manual than using the pretty-printer to do it. I would indeed be doing less manual work by letting the editor do it. (I'm arguing just to understand the reasoning behind this; I actually do it wrong and indent my ifs and unwind-protects manually to match Emacs' standard. I have been thinking about switching to Emacs lately, but still haven't done so.)

Unless your editor is very smart, it's making local decisions constantly, which may not be the same as the decisions it would make with the full context around. It's also more important for an editor to keep your code formatting stable than correct when you're changing stuff in the middle of an expression, so it may avoid making formatting changes that it would make otherwise, even if it detects that your code is now "incorrectly" formatted.

Plus, everyone uses PRETTY-PRINT, because it's built into the language, so everyone is used to the way pretty-printed code looks. Consistency is important.

(For example, the language Go that google developed has a pretty printer as well, which is *required* to be used as part of proper coding style.)
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Blank lines height

Postby tipo test » Tue Apr 19, 2011 10:06 am UTC

I like to leave blank lines between my constructions and the working code itself. I consider this

Code: Select all
      for (;;){
         
         while (){
            
            if (){
               
               doIt();
               
            }
            
         }
         
      }


far more legible than

Code: Select all
      for (;;){
         while (){
            if (){
               doIt();
            }
         }
      }


in real world examples. But sometimes leaving them looks excessive and not doing it does still does look ugly to my eyes. Are there any IDEs/editors supporting customable line height? I mean, if a line consists purely of spaces, tabs and carriage return, reduce automatically its height to half.

Btw, what's your opinion/approach in this matter?
User avatar
tipo test
 
Posts: 71
Joined: Sun May 23, 2010 12:15 pm UTC

PreviousNext

Return to Religious Wars

Who is online

Users browsing this forum: 3jd4061z and 4 guests