2009/6/10 Rajkumar Goel <rajkumargoel_...@...>

> Hi all,
> Can someone elaborate on the term side-effect.
>

Hello Rajkumar,

If a method takes no parameters, as in:

scala> def greet() = println("Hello, world!")
greet: ()Unit

 You can call it with or without parentheses:

scala> greet()
Hello, world!
unnamed7: Unit = ()

scala> greet
Hello, world!
unnamed8: Unit = ()

 The recommended style guideline for such method invocations is that if the
method may have *side effects*, you should provide the parentheses even if
the compiler doesn't require them. Thus in this case, since the greet method
prints to the standard output, it has side effects and you should invoke it
with parentheses to alert programmers looking at the code.

*** *A method has side effects if it changes state outside the method.
*
Hope this helps :)


-- 
Cheers,
Pratik K Anand


[Non-text portions of this message have been removed]

Reply via email to