News for hackers. Stuff that matters.
Re:C-style vs. Python-style syntax: which one would you pref... by ErrantX on Sunday December 14, 2008 @12:28PM (#397452)
As a multi language user I prefer the python style for the following reasons:

- It is easier on the eye, especially when somone else has to read through & understand it

- I find it quicker to code

That said there are some aspects where C-style is superior - so a combination of the 2 might work well! Invent your own "mash up" style (as long as it is not too confusing).

Re:C-style vs. Python-style syntax: which one would you pref... by carterschonwald on Sunday December 14, 2008 @12:45PM (#397468)
how about take a page from haskell style syntax, which allows both inferring the block structure from indentation, but also always it to be explicitly denoted at well?
Re:C-style vs. Python-style syntax: which one would you pref... by lincolnq on Sunday December 14, 2008 @02:53PM (#397589)
I've found that I really don't like this, aesthetically (mixing nesting styles in code looks bad)

Also, whitespace based indentation works in Python because Python statements tend to be fairly short. (The python indentation rules are easily understood.) Haskell layout has been somewhat more difficult to understand (at least for me). I have been writing Haskell code and usually it works, but there have been problems due to failure to indent when I should'v, which were incredibly confusing to debug.

In python, it's hard to fuck it up: after a colon, you always newline and indent.

Re:C-style vs. Python-style syntax: which one would you pref... by nuclear_eclipse on Sunday December 14, 2008 @03:21PM (#397605)
> In python, it's hard to fuck it up: after a colon, you always newline and indent.

But what about:

    if True: print "Yep"
;)
Re:C-style vs. Python-style syntax: which one would you pref... by whatusername on Sunday December 14, 2008 @06:06PM (#397743)
Get with the program:

if True: print("Yep")

Re:C-style vs. Python-style syntax: which one would you pref... by ljlolel on Sunday December 14, 2008 @06:07PM (#397744)
Don't do that: http://www.python.org/dev/peps/pep-0008/

Some features of Python are only really meant to be used at interactive prompts, like import STAR ( I can't write star?)

Re:C-style vs. Python-style syntax: which one would you pref... by nuclear_eclipse on Sunday December 14, 2008 @06:20PM (#397752)
Completely agreed; I was just pointing it out.
Re:C-style vs. Python-style syntax: which one would you pref... by FalconNL on Sunday December 14, 2008 @01:40PM (#397520)
Completely agree. The main reason for my preference is that one of the things I hate most in C-style languages is that one-line functions take up three or four lines (depending on whether or not you use K&R style). This greatly increases the amount of scrolling you have to do.
Re:C-style vs. Python-style syntax: which one would you pref... by mdakin on Sunday December 14, 2008 @04:18PM (#397665)
Put it all on one line then! :) I just grepped some of my C/C++ code and my one-liners consistently look like this:

virtual const std::string& getCommand() const throw() { return m_command ; }

Re:C-style vs. Python-style syntax: which one would you pref... by FalconNL on Sunday December 14, 2008 @05:01PM (#397693)
Yeah, that works for really short methods, but for anything even a little more complex you're just replacing vertical scrolling with horizontal scrolling.
Re:C-style vs. Python-style syntax: which one would you pref... by mdakin on Sunday December 14, 2008 @06:56PM (#397780)
That's true for one-liners in any language.
Re:C-style vs. Python-style syntax: which one would you pref... by FalconNL on Monday December 15, 2008 @02:18AM (#398136)
Not necessarily. In Haskell the oneliners are frequently short enough to fit on one screen.

For example, I recently needed to do some Run-Length Encoding:

    import Control.Arrow
    import Data.List
    
    encodeRLE :: (Eq a) => [a] -> [(Int, a)]
    encodeRLE = map (length &&& head) . group
    
    decodeRLE :: [(Int, a)] -> [a]
    decodeRLE = concatMap (uncurry replicate)
Re:C-style vs. Python-style syntax: which one would you pref... by mojuba on Sunday December 14, 2008 @12:38PM (#397459)
Something like

  if tyrant:
    divide(); conquer()
is possible. Mixing curly braces with Python-style though wouldn't be very nice, I think.
Re:C-style vs. Python-style syntax: which one would you pref... by ErrantX on Sunday December 14, 2008 @12:41PM (#397464)
Oh yeh I didnt mean that at all.

Indentation-as-a-divider is definitely easer on the eye than curly braces. But C-stlye has some handy bits and pieces to pick up (expecially on the OOP side of things - and also in the type-setting; though that has improved in python)

Re:C-style vs. Python-style syntax: which one would you pref... by mojuba on Sunday December 14, 2008 @12:49PM (#397476)
What you mean by the OOP side of things?

I find superlong indented blocks in Python a bit awkward, although can't explain why. When I look at a long class definition, for example, it just begs to be closed with end or "}". Small blocks though look definitely better without the block braces.

I'm thinking about introducing an optional end and leaving it to the taste of a programmer. Not sure yet.

Re:C-style vs. Python-style syntax: which one would you pref... by llimllib on Sunday December 14, 2008 @01:10PM (#397501)
Python already has an optional end:

    def something:
        alpha()
        omega()
    #end
I think introducing it as a special case, with no semantic value, into your parser would be an extremely poor idea.
Re:C-style vs. Python-style syntax: which one would you pref... by mojuba on Sunday December 14, 2008 @02:00PM (#397540)
True, except #end doesn't verify you are at the correct level of indentation. This, instead, would be more appropriate:

  def something:
    ...
  end def
but then it makes indentations insignificant altogether.
Re:C-style vs. Python-style syntax: which one would you pref... by llimllib on Sunday December 14, 2008 @02:11PM (#397558)
That would indeed make it semantically valuable. I assume you'd have "end while", "end if", etc?

I can't say I'm a fan, but at least you'd be making it mean something if you did that.

(Also: why make it optional at that point? Seems like it should be required for simplicity's sake)

Re:C-style vs. Python-style syntax: which one would you pref... by mojuba on Sunday December 14, 2008 @02:44PM (#397581)
Shell/Ruby style (if ... endif) is not even considered because I'm no fan of it either. I think it already lost the battle to both C and Python styles.

It would be nice, however, to have some optional verification mechanism that allowed you to stay minimalist for as long as you wish, and to use closing tags for verification and/or aesthetical reasons - for example, when closing a superlong block.

Re:C-style vs. Python-style syntax: which one would you pref... by newt0311 on Tuesday December 16, 2008 @11:24AM (#399608)
Woah... Be wary of that attitude for there lies the path to C++ hell. Like people say, the path to hell is paved with good intentions.
Re:C-style vs. Python-style syntax: which one would you pref... by ErrantX on Sunday December 14, 2008 @01:05PM (#397497)
That's quite a good idea.

My point with braces is that you dont have to indent the code then - which is dangerous :)

I have inherited a couple of PHP and C projects that have taken weeks just to indent to be readable - before i can even begin to work on them! (admittedly that is more of a PHP problem). Forced indentation makes definite that everything is obvious: addign curly braces is purely asthetic IMO :D

Re:C-style vs. Python-style syntax: which one would you pref... by davidw on Sunday December 14, 2008 @01:25PM (#397507)

    (defun indent-buffer ()
      "Indent entire buffer"
      (interactive)
        (indent-region (point-min) (point-max) nil))
Re:C-style vs. Python-style syntax: which one would you pref... by queensnake on Sunday December 14, 2008 @09:10PM (#397871)
The Unix 'indent' command has come a long way in the last few years, too.
Re:C-style vs. Python-style syntax: which one would you pref... by bkudria on Sunday December 14, 2008 @03:41PM (#397630)
Amen.
Re:C-style vs. Python-style syntax: which one would you pref... by potatolicious on Sunday December 14, 2008 @02:33PM (#397572)
I don't think it's the job of the programming language to enforce style. Proper code style should always be used, but should not be forced upon the coder, and that's my major objection to Python syntax.
Re:C-style vs. Python-style syntax: which one would you pref... by ljlolel on Sunday December 14, 2008 @06:12PM (#397748)
I don't think it's the job of human beings to enforce style. Proper code style should always be used automatically, but should not force the coder to waste a second thinking about it. The coder should think purely about the logic of the program, and that's my major objection to C.
Re:C-style vs. Python-style syntax: which one would you pref... by anthonyb on Sunday December 14, 2008 @06:22PM (#397755)
So proper code style should be forced on the maintainer instead?
Re:C-style vs. Python-style syntax: which one would you pref... by newt0311 on Sunday December 14, 2008 @03:54PM (#397645)
That's valid python.
Re:C-style vs. Python-style syntax: which one would you pref... by newt0311 on Sunday December 14, 2008 @01:00PM (#397492)
The not too confusing part is especially important. It is very difficult to cut features down and very easy to build them up. Simplicity is king.