[go: up one dir, main page]

|
|
Log in / Subscribe / Register

Missed opportunities

Missed opportunities

Posted Jun 10, 2013 8:11 UTC (Mon) by jezuch (subscriber, #52988)
In reply to: Missed opportunities by ncm
Parent article: Little things that matter in language design

> we sometimes see
>
> Ob::Ob
> ( int a
> , int b
> , int c
> )
> : _x( a + b - c)
> , _y( a - b + c)
> , _z(-a + b + c)
> {}
>
> enum T
> { T1
> , T2
> , T3
> };

I've seen it in some projects and I agree it's ugly as heck, even though I understand the intention behind it. In Java the parser allows "extra" commas after the last element in some places like array initalizers and enum declarations. I'm not sure if this was an accidental omission or intentional but it's quite useful, e.g.:

Object[] arr = new Object[] {
obj1,
obj2,
obj3,
}

enum Test {
TEST1,
TEST2,
TEST3,
;
}

But it's not allowed in parameter lists, alas.


to post comments

Missed opportunities

Posted Jun 10, 2013 11:03 UTC (Mon) by sorpigal (subscriber, #36106) [Link]

This is one of those little conveniences that I like about Perl: trailing commas are ignored (more or less), so you can say


my %map = (
    'one'   => 1,
    'two'   => 2,
    'three' => 3,
);

or in an argument list


sub bar{
    return join(',',@_);
}

print bar(
    1,
    2,
    3,
);
This is worth it even if only because the addition of a line to the map creates a one-line diff and not a two-line.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds