[Newbies] More than 256 literals referenced.

Robert Stehwien rstehwien at gmail.com
Mon Jul 23 23:37:07 UTC 2007


> The limit is 256 literals per method. However, a literal array is
> still just one literal. So you can put all your data into one literal
> if you want:
>
>         #((
>                 value 2
>                 cost -3
>                 step 2
>                 defense 3
>                 combatMove 7
>                 fullMove 14
>                 carry 10
>                 lift 20
>                 death 20
>                 unconscious 11
>                 woundThreshold 4
>                 recovery 05
>                 mysticArmor 0
>         ) (
>                 value 2
>                 cost -3
>                 step 2
>                 defense 3
>                 combatMove 7
>                 fullMove 14
>                 carry 10
>                 lift 20
>                 death 20
>                 unconscious 11
>                 woundThreshold 4
>                 recovery 05
>                 mysticArmor 0
>         ) )
>
> Then just iterate over it (#do: for the outer array, #pairsDo: is
> handy for the inner) to construct your objects. Btw, you surely would
> like to make a class and not just use dictionaries ;)
>

256 literals per method seems find to me, initializing such a large
dictionary was unusual for me and something of an experiment (mainly
to avoid reading from a file at all).  I had the data in YAML that I
just wrote a small script to generate smalltalk code from.

I didn't make a class mainly because I don't need the data for
anything more than lookups dictionaries give me.  I'll give your
suggestion above a try but might just convert the YAML to XML or CSV
and read the table in from the file.  Maybe as an array of RecordEntry
instead of using a dictionary.

I will have a need for a database (or some persistence layer) later in
the project, so might just bite the bullet now.

Thanks,
Robert


More information about the Beginners mailing list