This page is no longer maintained — Please continue to the home page at www.scala-lang.org

a style question

5 replies
Nilanjan Raycha...
Joined: 2009-11-06,
User offline. Last seen 42 years 45 weeks ago.
These days I am writing more code in Scala like the following

some_method_call match {
   case true => ...
   case false => ...
}

than standard if/else

if(some_method_call) ...
else ...

And I don't have a very good reason for it. Just wondering what you guys think/prefer?

Thanks
Nilanjan
Ngoc Dao
Joined: 2009-11-19,
User offline. Last seen 42 years 45 weeks ago.
Re: a style question

In that case, you may find yourself switching to Erlang easily :D

On Sat, Dec 19, 2009 at 7:40 AM, Nilanjan Raychaudhuri
wrote:
> These days I am writing more code in Scala like the following
>
> some_method_call match {
>    case true => ...
>    case false => ...
> }
>
> than standard if/else
>
> if(some_method_call) ...
> else ...
>
> And I don't have a very good reason for it. Just wondering what you guys
> think/prefer?
>
> Thanks
> Nilanjan

David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: a style question


On Fri, Dec 18, 2009 at 2:40 PM, Nilanjan Raychaudhuri <nraychaudhuri [at] gmail [dot] com> wrote:
These days I am writing more code in Scala like the following

some_method_call match {
   case true => ...
   case false => ...
}

than standard if/else

if(some_method_call) ...
else ...

And I don't have a very good reason for it. Just wondering what you guys think/prefer?

I tried that style back when I first started Scala.  I found that if/else is more concise and better describes a simple choice.  if/else is my preferred construct.
 

Thanks
Nilanjan



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
Nilanjan Raycha...
Joined: 2009-11-06,
User offline. Last seen 42 years 45 weeks ago.
Re: a style question
Funny you mention that , because I am actually porting one Erlang application to Scala right now. Maybe that's the influence.

On Sat, Dec 19, 2009 at 1:51 AM, Ngoc Dao <ngocdaothanh [at] gmail [dot] com> wrote:
In that case, you may find yourself switching to Erlang easily :D


On Sat, Dec 19, 2009 at 7:40 AM, Nilanjan Raychaudhuri
<nraychaudhuri [at] gmail [dot] com> wrote:
> These days I am writing more code in Scala like the following
>
> some_method_call match {
>    case true => ...
>    case false => ...
> }
>
> than standard if/else
>
> if(some_method_call) ...
> else ...
>
> And I don't have a very good reason for it. Just wondering what you guys
> think/prefer?
>
> Thanks
> Nilanjan

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: a style question
FWIW, and as a side node. 
One thing I _always_ miss in any language I use outside the Lisp/Scheme world is the "cond".   I'm sure there is a reason why "new" languages eschew cond for ye olde  if..then...elseif ... then ... elseif ... .  which was _the_ flow control construct since programs where poked with sharpened reeds into clay tablets.  
One would think various explorations in flow control syntax would be much richer after 50 years of language research and would be one of the primary differentiators of languages by language designers vis-a-vis what the language did and did not support.   Maybe its been shown nested ifthenelseifthenelse... hasn't been beaten.  But I do miss cond.
- 'case' has evolved into robust 'match'ing.- ifthenelseif has evolved into ... well ifthenelseif with at best subtle variations with regard to parens and brackets.  <yawn>
It seems languages with macros have them.  Macro-less languages tend not to have them.  I think Scala as it stands has sufficient flexibility to pull off and standardize some of them to varying degrees.  But to really get clean syntax, some may require primitive Scala syntax extension to really get correct.
Good library project for those with time.  A scalax flow control package with 'when', 'unless', 'cond' and 'if' and their anamorphic cousins (via Option).  I do miss cond.
Ray

On Fri, Dec 18, 2009 at 5:40 PM, Nilanjan Raychaudhuri <nraychaudhuri [at] gmail [dot] com> wrote:
These days I am writing more code in Scala like the following

some_method_call match {
   case true => ...
   case false => ...
}

than standard if/else

if(some_method_call) ...
else ...

And I don't have a very good reason for it. Just wondering what you guys think/prefer?

Thanks
Nilanjan



--
The object of life is not to be on the side of the majority, but to escape finding oneself in the ranks of the insane. - Marcus Aurelius
Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: a style question

http://code.google.com/p/scalaz/source/browse/trunk/core/src/main/scala/...

http://code.google.com/p/scalaz/source/browse/trunk/core/src/main/scala/...

-jason

On Mon, Dec 21, 2009 at 6:17 PM, Ray Racine wrote:
> FWIW, and as a side node.

> Good library project for those with time.  A scalax flow control package
> with 'when', 'unless', 'cond' and 'if' and their anamorphic cousins (via
> Option).  I do miss cond.
> Ray
>
> On Fri, Dec 18, 2009 at 5:40 PM, Nilanjan Raychaudhuri
> wrote:
>>
>> These days I am writing more code in Scala like the following
>>
>> some_method_call match {
>>    case true => ...
>>    case false => ...
>> }
>>
>> than standard if/else
>>
>> if(some_method_call) ...
>> else ...
>>
>> And I don't have a very good reason for it. Just wondering what you guys
>> think/prefer?
>>
>> Thanks
>> Nilanjan
>
>
>
> --
> The object of life is not to be on the side of the majority, but to escape
> finding oneself in the ranks of the insane. - Marcus Aurelius
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland