Forums

Syntactic relaxation on type declarations

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Syntactic relaxation on type declarations

Postby Charles » Sun Dec 07, 2008 9:07 pm

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?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Syntactic relaxation on type declarations

Postby gauthier » Sun Dec 07, 2008 9:59 pm

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
gauthier
 
Posts: 116

Re: Syntactic relaxation on type declarations

Postby gauthier » Sun Jan 04, 2009 7:29 am

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
gauthier
 
Posts: 116

Re: Syntactic relaxation on type declarations

Postby Charles » Sun Jan 04, 2009 11:43 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Syntactic relaxation on type declarations

Postby gauthier » Sun Jan 04, 2009 12:17 pm

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
gauthier
 
Posts: 116

Re: Syntactic relaxation on type declarations

Postby Charles » Sun Jan 04, 2009 12:31 pm

Yeah, but you need to paste in some examples so I can feel your pain. :-)
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Syntactic relaxation on type declarations

Postby Charles » Mon Feb 02, 2009 10:03 pm

I'm bumping this thread up to remind myself of this topic and outstanding work for it.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Syntactic relaxation on type declarations

Postby Charles » Mon Feb 23, 2009 11:32 pm

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: _
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 93 guests

cron