Poll: Wich grammatic genre do you favor?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Wich genre of grammar do you prefer?

Curly Bracketed (C family, perl, PHP, Java, etc.)
64
53%
LISP's (Lisp, Scheme, Joy, etc.)
10
8%
Indented languages (Python, BASIC, Ruby, etc.)
38
31%
Reverse Polish Notation (Forth, Post Script, Factor, etc. )
3
2%
Command based (Assembly languages, Batch languages, etc.)
3
2%
Unrestricted languages (Lua, io, etc.)
1
1%
Other (please specify)
2
2%
 
Total votes: 121

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Poll: Wich grammatic genre do you favor?

Postby MHD » Thu Apr 30, 2009 12:58 pm UTC

I was wondering what type of language layout you prefer programming with.

I prefer indented and curly.
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"

Nec
Posts: 54
Joined: Sun Dec 28, 2008 11:14 pm UTC
Contact:

Re: Poll: Which grammatic genre do you favor?

Postby Nec » Thu Apr 30, 2009 3:02 pm UTC

Definitely indented or curly. I indent all my code to being with (Im a neat coder :P), so making the move doesnt really bother me.

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Poll: Wich grammatic genre do you favor?

Postby Briareos » Thu Apr 30, 2009 3:14 pm UTC

Even though I now love Haskell, I just can't bring myself to choose "indented." Curly-bracket languages and Lisps are my favorites for looking at.
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

User avatar
zombiefeynman
Posts: 211
Joined: Thu Apr 02, 2009 4:16 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby zombiefeynman » Thu Apr 30, 2009 4:34 pm UTC

Got to go with curly. Indented reminds me too much of Python's restrictive attitude - you can't move your code around to emphasize certain things. I'm all for indenting code, but it shouldn't be required (I'm Libertarian like that :P ). Layout-based execution just rubs me the wrong way. I don't know too much about Lisp-style (though it looks kinda cool and I can at least read it).

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Poll: Wich grammatic genre do you favor?

Postby Qoppa » Thu Apr 30, 2009 4:38 pm UTC

I voted for curly and LISP style. Curly is my favourite, and definitely the easiest to read, but the LISP style makes sense once you get used to it. And as with zombiefeynman, I don't like being forced to indent my code a certain way. Admittedly, 99% of the time, that's how I would indent it anyway, but I still don't like not having a choice.

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
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Berengal » Thu Apr 30, 2009 5:33 pm UTC

Indented is the only style for me. Python may be restrictive, but Haskell isn't.
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.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Poll: Wich grammatic genre do you favor?

Postby 0xBADFEED » Thu Apr 30, 2009 5:42 pm UTC

Berengal wrote:Indented is the only style for me. Python may be restrictive, but Haskell isn't.

Haskell actually has the best of both worlds since you can choose to use Layout or to use the bracketed style.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Berengal » Thu Apr 30, 2009 5:59 pm UTC

Not to mention that choice can be made over and over instead of just once. I've only ever used brackets it in ghci, where everything's got to be on a single line. The layout is simply flexible and clever enough that you can lay your code out almost any way you want and have it run correctly.
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
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Poll: Wich grammatic genre do you favor?

Postby evilbeanfiend » Thu Apr 30, 2009 6:49 pm UTC

personally i'd prefer a language not specify any fixed grammar. closest i can think of to this is TCL which has a fixed, but really small grammar.
in ur beanz makin u eveel

dosboot
Posts: 143
Joined: Sun Jul 01, 2007 5:26 am UTC

Re: Poll: Wich grammatic genre do you favor?

Postby dosboot » Thu Apr 30, 2009 7:15 pm UTC

I voted 'other' for Haskell, but I see other people consider it to be under indented. Using a space for function application instead of paranetheses is really elegant.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Berengal » Thu Apr 30, 2009 7:38 pm UTC

Whitespace is the most valuable space, and the simple 'space' is the most valuable character of whitespace. It makes sense to make the most powerful operator be represented by a space.
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
zombiefeynman
Posts: 211
Joined: Thu Apr 02, 2009 4:16 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby zombiefeynman » Thu Apr 30, 2009 9:07 pm UTC

Berengal - you have convinced me that I really need to learn Haskell.

And as to whitespace - I agree that it is valuable, so I can understand giving it such power, but I also find it fickle. I am a little scared about entrusting the execution of my program to something that is kind of invisible. '{' and '}' are only visible because they are against the background, so I have a hard time respecting the background as anything other than the background.

It does produce very readable code, though - I can't deny that.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby hotaru » Fri May 01, 2009 6:39 am UTC

evilbeanfiend wrote:personally i'd prefer a language not specify any fixed grammar. closest i can think of to this is TCL which has a fixed, but really small grammar.

like factor? it has a really small grammar and allows you to modify the grammar yourself, so you can do things like this...

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

mrkite
Posts: 336
Joined: Tue Sep 04, 2007 8:48 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby mrkite » Fri May 01, 2009 8:56 am UTC

Without curly brackets, I would be lost... what would the '%' key in vim be used for?

User avatar
Qoppa
Posts: 694
Joined: Sat Nov 24, 2007 9:32 pm UTC
Location: Yes.

Re: Poll: Wich grammatic genre do you favor?

Postby Qoppa » Fri May 01, 2009 1:59 pm UTC

zombiefeynman wrote:Berengal - you have convinced me that I really need to learn Haskell.
Haha, I think I said that exact thing a few months back. It's totally worth it.

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
zombiefeynman
Posts: 211
Joined: Thu Apr 02, 2009 4:16 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby zombiefeynman » Fri May 01, 2009 2:34 pm UTC

Qoppa wrote:Haha, I think I said that exact thing a few months back. It's totally worth it.

I've installed GHC and downloaded a few tutorials. I feel like some mystic going into the hills with a waterskin and a flint knife. If I survive, I will have transcended this world (or something like that).

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Poll: Wich grammatic genre do you favor?

Postby evilbeanfiend » Fri May 01, 2009 4:50 pm UTC

hotaru wrote:
evilbeanfiend wrote:personally i'd prefer a language not specify any fixed grammar. closest i can think of to this is TCL which has a fixed, but really small grammar.

like factor? it has a really small grammar and allows you to modify the grammar yourself, so you can do things like this...


yes, though id be tempted to change RPN -> PN straight away, i want my DSLs to be easy for me to read, who cares about the parser.
in ur beanz makin u eveel

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Poll: Wich grammatic genre do you favor?

Postby MHD » Fri May 01, 2009 9:57 pm UTC

Berengal, your avatar and you love for haskell has made me go check it out.

I already love it.
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
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Xeio » Sat May 02, 2009 12:26 am UTC

I would love Haskell so much more without significant white space, but it is a quite elegant language otherwise.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Berengal » Sat May 02, 2009 12:54 am UTC

I believe we stated whitespace is only significant if you want it to be?
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
cerbie
Posts: 934
Joined: Sat Jul 05, 2008 5:14 am UTC
Location: USA

Re: Poll: Wich grammatic genre do you favor?

Postby cerbie » Sat May 02, 2009 8:40 pm UTC

How exactly are Lua and Io terribly special? Io is a bit more flexible, but I'm not really sure in what way either are "unrestricted" when it comes to grammar.

white-space controlled ("indented") and LISP-alikes for me.
DSenette: (...) on the whole, even a trained killer cow is kind of stupid.

Outchanter
Posts: 669
Joined: Mon Dec 17, 2007 8:40 am UTC

Re: Poll: Wich grammatic genre do you favor?

Postby Outchanter » Sun May 03, 2009 4:07 am UTC

I think BASIC is miscategorized here. Carriage returns are significant, but not indentation.

Indented seems to me the most efficient and legible, but the difference between indented and curly brace is fairly cosmetic since you could write a parser to translate more or less directly from one style to another. More interesting is the difference between Haskell style currying and C++ style overloading, which I think are incompatible, since C++ functions can be overloaded for varying numbers of arguments.

Also the difference between C++/Python style OOP and Haskell dispatch, since in C++ two unrelated classes can have member functions with the same name, while Haskell wants to know whether you're calling Map.toList or Set.toList. C++ could infer which function was needed from the argument, but I think Haskell is doing the opposite, i.e. trying to infer the type of the argument from the function...

Does Haskell have anything like Python's pickle module, btw?

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby hotaru » Sun May 03, 2009 5:03 am UTC

Outchanter wrote:More interesting is the difference between Haskell style currying and C++ style overloading, which I think are incompatible, since C++ functions can be overloaded for varying numbers of arguments.

i'm guessing you think functions in haskell can't take varying numbers of arguments...

Code: Select all

{-# OPTIONS -fglasgow-exts #-}

import Data.List

class BuildList a r  | r-> a where
    build' :: [a] -> a -> r

instance BuildList a [a] where
    build' l x = reverse$ x:l

instance BuildList a r => BuildList a (a->r) where
    build' l x y = build'(x:l) y

build :: BuildList a r => a -> r
build x = build' [] x

Code: Select all

*Main> build 1 :: [Int]
[1]
*Main> build 1 2 :: [Int]
[1,2]
*Main> build 1 2 3 :: [Int]
[1,2,3]

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Berengal » Sun May 03, 2009 5:10 am UTC

I once used that trick to write truth tables for predicates.
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.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Poll: Wich grammatic genre do you favor?

Postby 0xBADFEED » Sun May 03, 2009 2:41 pm UTC

Outchanter wrote:More interesting is the difference between Haskell style currying and C++ style overloading, which I think are incompatible, since C++ functions can be overloaded for varying numbers of arguments.

I think you may need to look up "overloading" or "currying" because I think you may be misunderstanding one (or both) of them. I don't really see what overloading has to do with currying, the two concepts are completely orthogonal. There's nothing that prevents overloading functions in a language that supports currying.

Typically overloading isn't used in type-inferred FP languages because the function signatures are usually used to drive the type inference, which is difficult (or ambiguous) when multiple functions may exist with alternate type signatures.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby Berengal » Sun May 03, 2009 2:51 pm UTC

Yeah, currying is simply transforming a function of type a*b -> c to a function of type a -> (b -> c), or in other words, transforming a function of several arguments to a function of one argument return a function taking the rest of the arguments. This can be done for all functions taking more than one argument.

What's making overloading hard (or rather, impossible) is type inference.
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
jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

Re: Poll: Wich grammatic genre do you favor?

Postby jemthealmighty » Sun May 03, 2009 11:47 pm UTC

Curly and indented for me.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby qbg » Mon May 04, 2009 3:24 am UTC

Lisp style. Of course, for full effect you would be including read macros, and that opens up another can of worms...

Outchanter
Posts: 669
Joined: Mon Dec 17, 2007 8:40 am UTC

Re: Poll: Wich grammatic genre do you favor?

Postby Outchanter » Mon May 04, 2009 6:16 am UTC

hotaru wrote:i'm guessing you think functions in haskell can't take varying numbers of arguments...

That's an interesting trick. I suppose the type declarations are necessary so it knows when to stop?

Berengal wrote:Yeah, currying is simply transforming a function of type a*b -> c to a function of type a -> (b -> c), or in other words, transforming a function of several arguments to a function of one argument return a function taking the rest of the arguments. This can be done for all functions taking more than one argument.

What's making overloading hard (or rather, impossible) is type inference.

I should have been more specific. By Haskell style currying, I meant automatically defining all functions as curried, and by C++ style overloading, I meant overloading only based on parameter number and type (apparently Ada can overload based on return type, which could change things). It seems allowing both of these would create ambiguities, since automatic currying would make

Code: Select all

int f(int a, int b)


callable either as f(a, b) or f(a)(b) with identical results. That would prevent you from defining an overloaded

Code: Select all

int f(int a)


since the compiler wouldn't know whether f(a) was of type int, as just defined, or (int -> int), as required for currying the earlier definition. I suppose Ada might be able to handle that by checking what type f(a) was expected to be. And as hotaru's example shows, it looks like Haskell can do something like that with a bit of trickery.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Poll: Wich grammatic genre do you favor?

Postby hotaru » Mon May 04, 2009 6:59 am UTC

Outchanter wrote:
hotaru wrote:i'm guessing you think functions in haskell can't take varying numbers of arguments...

That's an interesting trick. I suppose the type declarations are necessary so it knows when to stop?

no, the type declarations are necessary so it knows what type it is because the type of "build 1" could be either [Int] or Int -> [Int].
if you do something like this it's not necessary because it can figure out the type on it's own:

Code: Select all

*Main> ([0..5] !!) . last $ build 1
1
*Main> ([0..5] !!) . last $ build 1 2
2
*Main> ([0..5] !!) . last $ build 1 2 3
3

because the type of the second argument of (!!) has to be Int, which means that the return type of last has to be Int, and last's type is [a] -> a, so the type of the first argument of last in that expression has to be [Int].

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 22 guests