Re: Expression-local variables and 'let'
Daniel Bonniot <[email protected]>
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
>No doubt the differing views have to do with the coding styles being
>used. Seems like in Nice by default I use single assignment "let"
>throughout the code and then change to an explicit type or var if
>needed.
>
>These imperative usages read well:
> let s = shortName(c.getName);
>
>and as I use this form a lot, giving them up doesn't seem like a great
>idea.
>
>
I agree they read well.
Do you think
val s = ...;
does not read well? Or is your worry about the transition for 'legacy'
Nice code?
>It is a little scary to catch myself writing things like this ;-)
> let s = shortName(c.getName);
> let s' = s + ...
>
>
There is nothing wrong with that. I think it's actually quite good style
if you can give to s and s' different, meaningful names:
let shortName = ...;
let qualifiedName = packageName + "." + shortName;
then the declaration names actually provide documentation about your
code. if it's not the case, I'd personally prefer:
let meaningFulname = ... +
... + ... +;
>(maybe I should give-up and use a real fp language)
>
>
If you only want to use functional features, yes. On the other hand, the
advantage of using Nice is that together with this functional style, you
can benefit from "OO" features like method specialization which are hard
to emulate in a functional language. (And no, OCaml does not count,
because it provides both, but as separate features, you cannot combine
specialization (with objects) and pattern matching (with data types)).
Daniel
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click