Curly Brackets Go Where?

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

How do you do your bracketing?

Same line
88
48%
New line
88
48%
OTTERS!
7
4%
 
Total votes : 183

Re: Curly Brackets Go Where?

Postby Xanthir » Sat Mar 21, 2009 3:15 pm UTC

Philwelch wrote:
Xanthir wrote:
Philwelch wrote:Good luck with machine-generated code.

Um, what? I have no idea what that is supposed to mean as a response to my comment


It's easy to machine-generate brace-delimited blocks. Machine-generating whitespace-delimited blocks is more of a challenge: it turns your code generator (which is one project) into a code generator with a pretty-printer attached (which is two projects).

I thought that's what you meant, but that still has nothing to do with my statement. I said that whitespace is sufficient for human comprehension of the code; you countered with "but machines have a hard time generating that code". And?

For one, the other brace styles aren't *un*readable, just *less* readable to me. For two, you're actually looking at machine-generated code? The whole point of machine generation is that you don't look at it. If you're talking about machine-generated *scaffolding*, then you're working in the wrong language. Learn to use a functional language and stop making our eyes bleed.

As well, pretty-printers can be produced once and then reused everywhere, so there's no need to double the work in every project for that. So you have a code generator, which runs the generated code through an external pretty-print library once, at the end.

Xanthir wrote:
Don't whine to me about wasting whitespace, we aren't using teletypes anymore. Whitespace is cheap.

Um, no. Whitespace is *expensive* in terms of comprehension. The more you can comprehensibly fit into your eye, the better. Stretching a function out over a whole page when it can be compressed into less than half that space without losing comprehensibility is a crime.


Yes, but that's a question-begging way of putting it. "Without losing comprehensibility" is exactly the question here. And the better question is, "when and where does whitespace enhance comprehensibility"?

For instance:

Code: Select all
function(a, b, c){foo(a); bar(b); baz(c);}foo(x){fred(x+10)}fred(a){function(a, a, a);}


has no whitespace, and is thus unreadable, even though it fits within 80 columns or so.

Indeed, that *is* unreadable. Which is why I would never encourage it (thanks for the strawman, though!). My comments that you responded to explicitly recommended whitespace, in order to delimit blocks. If I was writing that code, it would be:
Code: Select all
function( a, b, c ) {
   foo(a);
   bar(b);
   baz(c);}
foo( x ) {
   fred(x+10)}
fred( a ) {
   function(a, a, a);}

Now look over BOTH blocks of code and tell me: where is the missing semicolon more apparent? (Yes, even if your compiler helpfully informs you what column your missing semicolon is on, and not just what line.)

Now that we've disposed of the false dilemna you attempted to employ to support your point, we can see that the error is equally obvious in both our code. Mine'll say "missing semicolon on line 6", and when you look at line 6, there it is!

Consider:

Phil's shopping list wrote:Bagels
Dishwasher soap
Bratwurst
K-Y Jelly


vs.
kriel's shopping list wrote:Bagels, dishwasher soap, bratwurst, and K-Y jelly.


In code:

Code: Select all
if (
    gotBagels() &&
    gotDishwasherSoap() &&
    gotBratwurst() &&
    gotKYJelly() &&
    )
  leaveStore();


vs.

Code: Select all
if (gotBagels() && gotDishwasherSoap() && gotBratwurst() && gotKYJelly())
  leaveStore();

At this point neither are good. The correct way to do this is:
Code: Select all
if( gotAllOnList( list, cart ) ) {
  leaveStore();
}

If you have to worry about how to format a conditional, you're doing it wrong. Refactor. There's no need to have formatting wars over conditionals, because by the time it becomes necessary you've already lost.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 3989
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Curly Brackets Go Where?

Postby TheOrangeMan » Mon Mar 23, 2009 12:22 am UTC

on a new line and indented, just as nature intended.
Science is like math turned inside out.
User avatar
TheOrangeMan
 
Posts: 25
Joined: Wed Feb 27, 2008 4:29 am UTC
Location: Directlly above you... IN THE FOURTH DIMENSION :O

Re: Curly Brackets Go Where?

Postby 0xBADFEED » Mon Mar 23, 2009 2:13 pm UTC

TheOrangeMan wrote:on a new line and indented, just as nature intended.

Do you mean like GNU style :
Code: Select all
if(x)
  { 
    do_something();
  }

or Whitesmiths style ?
Code: Select all
if(x)
    {
    do_something();
    }

Actually, I guess it doesn't really matter. They're both about equally horrendous to look at, with Whitesmiths being slightly less bad.
0xBADFEED
 
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Curly Brackets Go Where?

Postby enk » Tue Jun 16, 2009 12:02 pm UTC

This is kind of a necro. But there's a whole new aspect to this topic:

Code: Select all
MAIN()
  IO.write("Hello, World!\n")
}


http://www.zimbu.org/
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby ash.gti » Tue Jun 16, 2009 1:45 pm UTC

Oh god you can't even tell where it starts...
# drinks WAY to much espresso
User avatar
ash.gti
 
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: Curly Brackets Go Where?

Postby zombiefeynman » Tue Jun 16, 2009 2:40 pm UTC

Heck, I'd use GNU Style before I'd use that...thing.
User avatar
zombiefeynman
 
Posts: 211
Joined: Thu Apr 02, 2009 4:16 pm UTC

Re: Curly Brackets Go Where?

Postby lulzfish » Tue Jun 16, 2009 5:02 pm UTC

edit: I think the forum ate my indentation.
Pretend that this post is indented properly!

I like same-line.
The time I tried to use Python, I remember that the indentation thing threw me off a lot.

It's a good idea, but I want code to look like this:

class blah
stuff
stuff
end class

The C / C++ / Java style is a nice compromise:

class blah {
stuff
stuff
}

But Python leaves the end open, and I can't tell at a glance where the block ends:

class blah
stuff
stuff

?? class ends? maybe, maybe not.. Visually unsettling.
This bothers me more than the positioning of brackets, by far.
Last edited by lulzfish on Sun Jun 21, 2009 11:38 am UTC, edited 1 time in total.
User avatar
lulzfish
 
Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

Re: Curly Brackets Go Where?

Postby enk » Wed Jun 17, 2009 12:50 pm UTC

ash.gti wrote:Oh god I can't even tell where it starts...


Fixed that for you.
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby ash.gti » Wed Jun 17, 2009 6:29 pm UTC

Okay, granted I don't know all the grammar of that language, it does seem somewhat... illogical that they have a random character to end a block segment that is traditionally paired. Most people that see a { will look for the closing } to find the end, same goes in the other direction, if you noticed a ) wouldn't you try to see where that ended? It would almost make more sense if the language took a more functional approach and said

Code: Select all
MAIN(
  ...block content...
)


because at least then we'd have a logically matching pair of characters that encompasses a block. The closing '}' character has no logical purpose because the language isn't giving us a reason to expect a character as a block closing argument when it already used a word to start the block with no significant indication a block is being started.
# drinks WAY to much espresso
User avatar
ash.gti
 
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: Curly Brackets Go Where?

Postby enk » Sun Jun 21, 2009 7:18 am UTC

ash.gti wrote:Okay, granted I don't know all the grammar of that language, it does seem somewhat... illogical that they have a random character to end a block segment that is traditionally paired. Most people that see a { will look for the closing } to find the end


Well, I just posted it to spark interest to follow the link.

http://www.zimbu.org/, among other things, wrote:The } character is used to end a block. There is no {, we know where the block starts. This avoids useless discussions about where to put the {.


An unorthodox move, sure. But still noteworthy.
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby Philwelch » Sun Jun 21, 2009 9:35 am UTC

There are certain things that just break the human brain sometimes. Using an end bracket, end paranthesis, or the like without a matching opening character is one of them (with the exception of emoticons). People like symmetry, which is why even weird attempts at symmetry (i.e. "fi" to end an if block in shell scripting) are better than that.
Fascism: If you're not with us you're against us.
Leftism: If you're not part of the solution you're part of the problem.

Perfection is an unattainable goal.
Philwelch
 
Posts: 2904
Joined: Tue Feb 19, 2008 5:33 am UTC
Location: RIGHT BEHIND YOU

Re: Curly Brackets Go Where?

Postby Berengal » Sun Jun 21, 2009 9:38 pm UTC

Also: Tags vs parens. I should really finish my sexpr <-> xml converter and restore some of the sanity I've lost...
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: Curly Brackets Go Where?

Postby Gaydar2000SE » Wed Jun 24, 2009 10:13 am UTC

Depends , if my code should be readable to others:
Code: Select all
//this function shall do the thing that's immediately visible from it but because I think you are stupid, I'm going to put it here any way
function prime_counter($max_int) {
   
   $i = 1;
   
   while ($i <= $max_int) {
   
      $j = 2;
      
      while($j < $i) {
      //this part is dead obvious, if the remainter is zero it is divisible, zero evaluates to false.
      if($i % $j) {
      $string .= "divisible by $j; ";
      
      }
      $j++;
      }
      
      //this part is also obvious, but I'm going to explain it as I expect my readers to be stupid
      if (!$string) {
      
      $string = "$i is prime; ";
      $list[$i]['is_prime'] = true;
      $number_of_primes++;
      } else {
      
      $list[$i]['is_prime'] = false;
      }
      
      $list[$i]['details'] = $string;
   $i++;
   }
   
   
   $list['number_of_primes'] = $number_of_primes++;
   
   return $list;
   
}




If it's for myself only:

Code: Select all
function nrfx($kjlr) { $i = 1; while ($i <= $kjlr) { $j = 2;

while($j < $i) {
if($i % $j) { $strLOLAIDSLOL .= "divisible by $j; ";}$j++;}
if (!strLOLAIDSLOL) {$string = "$i is prime; ";$list[$i]['is_prime'] = true;$number_of_primes++;} else {

$list[$i]['is_prime'] = false;} $list[$i]['details'] = $string $i++; }$list['number_of_primes'] = $number_of_primes++;return $list;}


^ :/
User avatar
Gaydar2000SE
 
Posts: 210
Joined: Sun Jun 21, 2009 1:43 am UTC

Re: Curly Brackets Go Where?

Postby Reg Berkeley » Sat Jun 27, 2009 8:16 pm UTC

I prefer new line, disregarding the effect of whitespace.
Reg Berkeley
 
Posts: 6
Joined: Sun Jun 14, 2009 11:07 pm UTC

Re: Curly Brackets Go Where?

Postby Gaydar2000SE » Sun Jun 28, 2009 1:42 pm UTC

About that discussion above, people, and a lot tend to forget that different people have different tastes and find different things readable. I'm personally on the far end and find verdana, 5pt, #050505 on #000000 quite readable in normal daylight, though not at night. Also, larger texts decreases readability for me, as does a higher contrast which tires my eyes. #FAFAFA on #FFFFFF is also good but still I'd rather have it inverted. The reason larger text decreases readability for me is because I read multiple lines at the same time and just add them together at the end. It's rare but it makes sure I never read any adds on posters because the lines are too big and too far apart, and I can't catch multiple lines in my focal point, thus making it extremely tiresome for me to read a story if I can only read one line at a time. Just to show the extreme possibilities, I know of at least one other person that expressed similar discontent so it should not be that rare.

Same of course with whitespaces in programming blocks, people often forget quite often that different people have different needs. A lot of parenting magazines are profoundly lacking in realizing (or commercially ignoring) that different children have different needs and at max your advice will only be good for 60 per cent of the children, and may very compromise the rest.
ash.gti wrote:Okay, granted I don't know all the grammar of that language, it does seem somewhat... illogical that they have a random character to end a block segment that is traditionally paired. Most people that see a { will look for the closing } to find the end, same goes in the other direction, if you noticed a ) wouldn't you try to see where that ended? It would almost make more sense if the language took a more functional approach and said

Code: Select all
MAIN(
  ...block content...
)


because at least then we'd have a logically matching pair of characters that encompasses a block. The closing '}' character has no logical purpose because the language isn't giving us a reason to expect a character as a block closing argument when it already used a word to start the block with no significant indication a block is being started.
The key here is that it makes compiling or interpreting that much faster. Programming languages are also written with that in mind. In theory you can even do

Code: Select all
function_name argument1 argument2 argument 3;
block of code;

function_name ...




But then the parser first has to check the line, then conclude that it doesn't match a normal expression by all comparisons, and then conclude that it is a function. Whereas a string sans a space followed by '(' can immediately be concluded as a function, thus sparing time.
^ :/
User avatar
Gaydar2000SE
 
Posts: 210
Joined: Sun Jun 21, 2009 1:43 am UTC

Re: Curly Brackets Go Where?

Postby enk » Sun Jun 28, 2009 8:52 pm UTC

Gaydar2000SE wrote:[...] the parser first has to check the line, then conclude that it doesn't match a normal expression by all comparisons, and then conclude that it is a function. Whereas a string sans a space followed by '(' can immediately be concluded as a function, thus sparing time.


[citation needed]
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby Rysto » Sun Jun 28, 2009 9:18 pm UTC

I can't give a cite, but I can tell you that such a language would not be LR(1), which means that parsing it would quite inefficient(and there are few parsing tools out there that can handle non-LR(1) languages). I'm not even sure if a GLR parser would suffice.

To prove that it's not LR(1), consider the example already given:

Code: Select all
function_name1 argument1 argument2 argument 3;
block of code;

function_name2 ;

When the parser has the token function_name2 in its lookahead buffer, it has to decide whether the function definition has ended(because a new function definition is starting) or whether to continue parsing statements from function_name1. The token function_name2 doesn't give enough information to make that decision. If the token following function_name2 is a := then it must be an assignment statement; if it's a semi-colon it must be a function definition. But this is a LR(1) parser, so it's only allowed to look at one token of lookahead, so it doesn't have enough information to make the decision.
Rysto
 
Posts: 1420
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Curly Brackets Go Where?

Postby enk » Sun Jun 28, 2009 10:41 pm UTC

I don't completely get that example, but the parser doesn't need to know what it's looking at from one token to have a lookahead of one, does it?

I mean..

Code: Select all
int foo;
int bar();


and C is LR(1) iirc.
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby Rysto » Sun Jun 28, 2009 10:59 pm UTC

enk wrote:I don't completely get that example, but the parser doesn't need to know what it's looking at from one token to have a lookahead of one, does it?

I mean..

Code: Select all
int foo;
int bar();


and C is LR(1) iirc.

C isn't even an unambiguous language, let alone LR(1). In your particular example it doesn't matter because the parse can keep shifting tokens before deciding to reduce them into a declaration. In my example, if function_name2 begins a new function definition then the parser must reduce the previous statements into a function definition while function_name2 is still at the beginning of the lookahead buffer. Once the token is shifted onto the stack it must be a part of the next reduction, so shifting the token function_name2 means that the parser cannot reduce the statements preceding it into a function declaration.
Rysto
 
Posts: 1420
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Curly Brackets Go Where?

Postby enk » Sun Jun 28, 2009 11:27 pm UTC

Rysto wrote:C isn't even an unambiguous language, let alone LR(1)


Aren't you thinking of C++?
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby Rysto » Mon Jun 29, 2009 1:46 am UTC

enk wrote:
Rysto wrote:C isn't even an unambiguous language, let alone LR(1)


Aren't you thinking of C++?

No, although C++ is even worse, with Stroustrup taking the terrible syntax of C and hacking it to bits.

Consider the following:
f * y;

f (a);

The interpretation of either depends on whether f has been previously declared as a typedef name.
Rysto
 
Posts: 1420
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Curly Brackets Go Where?

Postby enk » Mon Jun 29, 2009 9:38 am UTC

Rysto wrote:
enk wrote:
Rysto wrote:C isn't even an unambiguous language, let alone LR(1)


Aren't you thinking of C++?

No, although C++ is even worse, with Stroustrup taking the terrible syntax of C and hacking it to bits.

Consider the following:
f * y;

f (a);

The interpretation of either depends on whether f has been previously declared as a typedef name.


Yeah, ok.

I misunderstood the example gaydar posted as well. Go me. And go offtopic :)
phlip wrote:Ha HA! Recycled emacs jokes.
User avatar
enk
 
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark

Re: Curly Brackets Go Where?

Postby Random832 » Mon Jun 29, 2009 12:31 pm UTC

I use a style of coding that does not require curly brackets:
Code: Select all
if (a != 1) goto lbl;
    //stuff
lbl:
GENERATION 99: The first time you see this, copy it into your sig on any forum and subtract 1 from the generation. Social experiment.
Random832
 
Posts: 2462
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Curly Brackets Go Where?

Postby 666alphaomega666 » Tue Jul 07, 2009 4:29 am UTC

apparently, i tied it up. awesome.

yea, new line definitely. i just think it looks much more... even.
Code: Select all
public static void main(String[] args) {
//god i hate this method already
}

public int symmetry()
{
//wonderful.
}
User avatar
666alphaomega666
 
Posts: 8
Joined: Fri Jul 03, 2009 1:33 am UTC

Re: Curly Brackets Go Where?

Postby stephentyrone » Tue Jul 07, 2009 2:53 pm UTC

Random832 wrote:I use a style of coding that does not require curly brackets:
Code: Select all
if (a != 1) goto lbl;
    //stuff
lbl:


Win.
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: Curly Brackets Go Where?

Postby Qoppa » Tue Jul 07, 2009 4:56 pm UTC

After spending the past two months coding with Java for a class, I'm now much more tolerable of putting curly brackets on the same line. Nevertheless, I will continue to put them on a new line when coding in C or C++.
Code: Select all
_=0,w=-1,(*t)(int,int);a()??<char*p="[gd\
~/d~/\\b\x7F\177l*~/~djal{x}h!\005h";(++w
<033)?(putchar((*t)(w??(p:>,w?_:0XD)),a()
):0;%>O(x,l)??<_='['/7;{return!(x%(_-11))
?x??'l:x^(1+ ++l);}??>main(){t=&O;w=a();}
User avatar
Qoppa
 
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Curly Brackets Go Where?

Postby hotaru » Tue Jul 07, 2009 7:19 pm UTC

666alphaomega666 wrote:apparently, i tied it up. awesome.

yea, new line definitely. i just think it looks much more... even.
Code: Select all
public static void main(String[] args) {
//god i hate this method already
}

public int symmetry()
{
//wonderful.
}

how is that more even than this?
Code: Select all
int some_function()
{ /* some code
     goes here */
  return 0; }
Code: Select all
#include <stdio.h>

int main()
{
 struct { unsigned a:3, b:3, c:2; } n = {0};
  do do printf("%hhu\n", *&n);
  while(!(n.a-- && !++n.b));
  while(++n.c);
  return 0; } 
User avatar
hotaru
 
Posts: 931
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Curly Brackets Go Where?

Postby 666alphaomega666 » Tue Jul 07, 2009 10:25 pm UTC

theyre vertically aligned, and vertically aligned things are sexy.
User avatar
666alphaomega666
 
Posts: 8
Joined: Fri Jul 03, 2009 1:33 am UTC

Re: Curly Brackets Go Where?

Postby hotaru » Wed Jul 08, 2009 4:09 am UTC

666alphaomega666 wrote:theyre vertically aligned, and vertically aligned things are sexy.

vertically aligned curly brackets look like this:
Code: Select all
  {
   }

not like this:
Code: Select all
{
}
Code: Select all
#include <stdio.h>

int main()
{
 struct { unsigned a:3, b:3, c:2; } n = {0};
  do do printf("%hhu\n", *&n);
  while(!(n.a-- && !++n.b));
  while(++n.c);
  return 0; } 
User avatar
hotaru
 
Posts: 931
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Curly Brackets Go Where?

Postby Philwelch » Wed Jul 08, 2009 4:30 am UTC

No. *horizontally* aligned curly brackets look like

Code: Select all
{}


*vertically* aligned curly brackets look like

Code: Select all
{
}


and *diagonally* aligned curly brackets look like

Code: Select all
 {
  }
Fascism: If you're not with us you're against us.
Leftism: If you're not part of the solution you're part of the problem.

Perfection is an unattainable goal.
Philwelch
 
Posts: 2904
Joined: Tue Feb 19, 2008 5:33 am UTC
Location: RIGHT BEHIND YOU

Re: Curly Brackets Go Where?

Postby hotaru » Wed Jul 08, 2009 5:28 am UTC

Philwelch wrote:*vertically* aligned curly brackets look like

Code: Select all
{
}

and i suppose you think this is the correct way to align numbers:
Code: Select all
  1.234
  12.34
  123.4

rather than this:
Code: Select all
    1.234
   12.34
  123.4
Code: Select all
#include <stdio.h>

int main()
{
 struct { unsigned a:3, b:3, c:2; } n = {0};
  do do printf("%hhu\n", *&n);
  while(!(n.a-- && !++n.b));
  while(++n.c);
  return 0; } 
User avatar
hotaru
 
Posts: 931
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Curly Brackets Go Where?

Postby Area Man » Wed Jul 08, 2009 7:36 pm UTC

hotaru wrote:
Philwelch wrote:*vertically* aligned curly brackets look like

Code: Select all
{
}

and i suppose you think this is the correct way to align numbers:
Code: Select all
  1.234
  12.34
  123.4

rather than this:
Code: Select all
    1.234
   12.34
  123.4

That's a completely faulty comparison: brackets and words are not place-value dependent; they have neither magnitude columns nor a common centre, you only indent them.
You can write either flush-right or left, but only numbers have to be 0-padded on a (respective) side for proper decimal alignment.

Code: Select all
BEGIN
     END;
is not aligned, it's staggered.
Additionally, such spacing is an *error* in an indentation-delimited language.
Bisquick boxes are a dead medium.
User avatar
Area Man
 
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

Re: Curly Brackets Go Where?

Postby Random832 » Wed Jul 08, 2009 7:40 pm UTC

Area Man wrote:Additionally, such spacing is an *error* in an indentation-delimited language.

Um, don't indentation-delimited languages kind of not have END keywords or brackets?
GENERATION 99: The first time you see this, copy it into your sig on any forum and subtract 1 from the generation. Social experiment.
Random832
 
Posts: 2462
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Curly Brackets Go Where?

Postby Area Man » Wed Jul 08, 2009 8:10 pm UTC

I seem to recall vb enforcing indentation while requiring such verbosity in addition.
Nevertheless:
Code: Select all
    fooz.member = 1;
  animal.cow;
     obj.func();
 roosters.create();
is a fucked up way to write code.
User avatar
Area Man
 
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

Re: Curly Brackets Go Where?

Postby ash.gti » Wed Jul 08, 2009 8:38 pm UTC

Area Man wrote:I seem to recall vb enforcing indentation while requiring such verbosity in addition.
Nevertheless:
Code: Select all
    fooz.member = 1;
  animal.cow;
     obj.func();
roosters.create();

is a fucked up way to write code.


If, for whatever reason, you do want to line up the dots in a lot of languages you can add whitespace between the object and the .method_name, like:

Code: Select all
fooz    .member = 1;
animal  .cow;
obj     .func();
roosters.create();


but i honestly wouldn't do that either.
# drinks WAY to much espresso
User avatar
ash.gti
 
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: Curly Brackets Go Where?

Postby Berengal » Wed Jul 08, 2009 9:23 pm UTC

Anyone done this before? *Checks thread*. Not in this thread at least.
Code: Select all
>>> from __future__ import braces
SyntaxError: not a chance (<pyshell#58>, line 1)

Brackets are dumb.
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: Curly Brackets Go Where?

Postby Philwelch » Thu Jul 09, 2009 2:19 am UTC

ash.gti wrote:
Area Man wrote:I seem to recall vb enforcing indentation while requiring such verbosity in addition.
Nevertheless:
Code: Select all
    fooz.member = 1;
  animal.cow;
     obj.func();
roosters.create();

is a fucked up way to write code.


If, for whatever reason, you do want to line up the dots in a lot of languages you can add whitespace between the object and the .method_name, like:

Code: Select all
fooz    .member = 1;
animal  .cow;
obj     .func();
roosters.create();


but i honestly wouldn't do that either.


Dots are a dumb thing to line up, but other things work out alright.

Code: Select all
       FOO       = 120
       FOOBAR    =  40
       QUASIMODO =   6
 
       if ( foo        ==  FOO       ||
            bar        ==  QUASIMODO ||
            salamander ==  FISHSTICKS
          )
Fascism: If you're not with us you're against us.
Leftism: If you're not part of the solution you're part of the problem.

Perfection is an unattainable goal.
Philwelch
 
Posts: 2904
Joined: Tue Feb 19, 2008 5:33 am UTC
Location: RIGHT BEHIND YOU

Re: Curly Brackets Go Where?

Postby hotaru » Thu Jul 09, 2009 5:06 am UTC

Area Man wrote:That's a completely faulty comparison: brackets and words are not place-value dependent; they have neither magnitude columns nor a common centre, you only indent them.

brackets do have a common center, to the right of the opening bracket and to the left of the closing bracket.
also, do you really say /ˈsɛntreɪ/, or just spell it that way?
Code: Select all
#include <stdio.h>

int main()
{
 struct { unsigned a:3, b:3, c:2; } n = {0};
  do do printf("%hhu\n", *&n);
  while(!(n.a-- && !++n.b));
  while(++n.c);
  return 0; } 
User avatar
hotaru
 
Posts: 931
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Curly Brackets Go Where?

Postby phlip » Thu Jul 09, 2009 5:17 am UTC

Along with spelling it differently, it seems we have a different definition of the word "centre"... see, we don't usually define it to mean "a point on the edge of something".
While no one overhear you quickly tell me not cow cow.
but how about watch phone?
User avatar
phlip
Restorer of Worlds
 
Posts: 6732
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia

Re: Curly Brackets Go Where?

Postby hotaru » Thu Jul 09, 2009 5:23 am UTC

phlip wrote:Along with spelling it differently, it seems we have a different definition of the word "centre"... see, we don't usually define it to mean "a point on the edge of something".

so what would you call the point in the middle of a set of brackets?
Code: Select all
#include <stdio.h>

int main()
{
 struct { unsigned a:3, b:3, c:2; } n = {0};
  do do printf("%hhu\n", *&n);
  while(!(n.a-- && !++n.b));
  while(++n.c);
  return 0; } 
User avatar
hotaru
 
Posts: 931
Joined: Fri Apr 13, 2007 6:54 pm UTC

PreviousNext

Return to Religious Wars

Who is online

Users browsing this forum: No registered users and 3 guests