Page 1 of 1

Syntactic relaxation on type declarations

PostPosted: Sun Dec 07, 2008 9:07 pm
by Charles
The current syntax starts with:
class <ClassName>
[is <AccessModifiers>]
[has <Attributes>]
[inherits <BaseClassName>]
...

The relaxation would be:

(1) Allow those three parts (is, has, inherits) on the same line as "class ..."

(2) Allow them in any order.

So you could say:
class Foo inherits Bar is internal
def baz
pass

While Cobra has generally favored having a uniform syntax between developers, I have found the current strict syntax for class declarations to be annoying. At least one other person has brought this up.

This would apply to "interface" and "struct" as well.

Comments?

Re: Syntactic relaxation on type declarations

PostPosted: Sun Dec 07, 2008 9:59 pm
by gauthier
Since I can't find a logical order for them (I would put has first or last but not in the middle), the relaxation seems good to me

Re: Syntactic relaxation on type declarations

PostPosted: Sun Jan 04, 2009 7:29 am
by gauthier
allowing newline and optional tab when enumerating any type (and parameter) list would be great (there is also issue with fluent interfaces which must be one-liner in cobra):

namespace here

interface IFoo
pass
interface IBar
pass
interface IBaz
pass

class FledgedFoo
inherits IFoo
, IBar
, IBaz

class Program
def main is shared
foo = FledgedFoo()
print foo

Re: Syntactic relaxation on type declarations

PostPosted: Sun Jan 04, 2009 11:43 am
by Charles
What's wrong with:
implements IFoo, IBar, IBaz

?

Also, regarding expressions, Cobra allows implicit line continuation inside parenthesis:
.foo(x,
y,
z)

You can also continue a line with an underscore (_) like in VB (also like the \ in Python).

Regarding fluent interfaces, perhaps we could also allow implicit line continuation if the next line starts with a dot (.):
foo.bar
.baz(a, b)
.qux(c, d)

Although I would want some real fluent examples first before working on that.

Re: Syntactic relaxation on type declarations

PostPosted: Sun Jan 04, 2009 12:17 pm
by gauthier
what's wrong with: implements IFoo, IBar, IBaz?


the problem with one-liner implements is when you use generic type, it's getting far more readable

interface IHasGetByKey<of TEntity, TEntityKey>
def getByKey(key as TEntityKey) as TEntity

interface IHasSaveEntityMethod<of TEntity>
def save(entity as TEntity)

interface IFooRepository
inherits IBaseRepository
, IHasGetByKey<of FooKey>
, IHasSaveEntityMethod<of Foo>
pass


seems more readable than an oneliner

Also, regarding expressions, Cobra allows implicit line continuation inside parenthesis:


they are fine (the continuation is good to know if problem occur without it)

Although I would want some real fluent examples first before working on that.


I'm dealing with NHibernate + NHibernateQueryGenerator code base and it relies on fluent interfaces and operator overloads, there is also Castle.Windsor which have fluent registration API I would like to use with cobra

Re: Syntactic relaxation on type declarations

PostPosted: Sun Jan 04, 2009 12:31 pm
by Charles
Yeah, but you need to paste in some examples so I can feel your pain. :-)

Re: Syntactic relaxation on type declarations

PostPosted: Mon Feb 02, 2009 10:03 pm
by Charles
I'm bumping this thread up to remind myself of this topic and outstanding work for it.

Re: Syntactic relaxation on type declarations

PostPosted: Mon Feb 23, 2009 11:32 pm
by Charles
The syntactic relaxations around type declarations (classes, structs, interfaces) are now done. Example:
class A inherits B
pass

struct C is partial
pass

class D inherits A is internal
pass

interface E inherits F
pass

class G inherits A
implements IDisposable
is internal

def dispose
pass

You can put the "type specifications" such as "inherits", "is", "has" and "implements" in any order. You can put them on the same line and/or separate lines.

For line continuations, such as a long "implements" clause, you can use the line continuation character: _