About enumerations.

old Java way:
public int MENU_FILE = 0; public int MENU_EDIT = 1; public int MENU_FORMAT = 2; public int MENU_VIEW = 3;

I'd write that as

public int MENU_FILE = 0, MENU_EDIT = 1, MENU_FORMAT = 2, MENU_VIEW = 3;
making it not that much worse than your Perl way, even though I agree that manually doing several assignments isn't satisfactory.

Well, Perl already have an easy way to declare a sequence of numbers, so, we don't need a enum word.

Your Perl way isn't satisfactory either though. Keeping track of how many variables/constants you have shouldn't be necessary. That's why I like the enum module. It has nice other features too, such as prefixes and bitmask enumerations.

use enum qw/ :MENU_ FILE EDIT FORMAT VIEW /;

ihb

Read argumentation in its context!


In reply to Re: J2SE 5.0 new features are just sugar from Perl (and other similar languages). by ihb
in thread J2SE 5.0 new features are just sugar from Perl (and other similar languages). by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":