Comments on Programming Scalaurn:uuid:51cc2a2e-2245-33bf-9afa-dd15eb1ba4422009-08-11T20:57:56-07:00 <div>A Taste of Concurrency <p id="para_the_actor_is_declared_to_be_pa">The actor is declared to be part of the <code class="literal">shapes</code> package. Next, we have two import statements.</p> <blockquote><p>ShapeDrawingActor is also defined as a singleton (object). Assume that is necessary, but why? </p> &#8212; maddalab (2009-07-26 08:14:24) </blockquote> </div>urn:uuid:16b41c0f-9233-37aa-b27b-a174eb8a238amaddalab2009-07-26T08:14:24-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_actor_is_declared_to_be_pa">The actor is declared to be part of the <code class="literal">shapes</code> package. Next, we have two import statements.</p> <blockquote><p>ShapeDrawingActor is also defined as a singleton (object). Assume that is necessary, but why? </p> &#8212; maddalab (2009-07-26 08:14:24) </blockquote> </div>urn:uuid:3061519a-9b6a-3038-9e58-aeb65123429bmaddalab2009-07-26T08:14:24-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_now_that_we_have_defined_our_s">Now that we have defined our shapes types, let&#8217;s return to actors. We define an <code class="literal">Actor</code> that receives &#8220;messages&#8221; that are shapes to draw.</p> <blockquote><blockquote><blockquote><p>since the implementations would depend on details like the operating system platform, graphics API </p> </blockquote></blockquote><p>not when running on the JVM. I agree that draw should not be in the domain model classes for the reason in your comment above "separation of concerns" not for the reasons in the Notes section. </p> <p>OS is a concern that is abstracted away by the virtual machine </p> &#8212; maddalab (2009-07-26 07:44:48) </blockquote> </div>urn:uuid:9285a2f8-f823-3399-8f63-31b7eebcd810maddalab2009-07-26T07:44:48-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para__rectangle_is_also_a_concrete"><code class="literal">Rectangle</code> is also a concrete subclass of <code class="literal">Shape</code> that defines <code class="literal">draw</code> and overrides <code class="literal">toString</code>. For simplicity, we assume it is not rotated relative to the X and Y axes. Hence, all we need is one point, the lower left-hand point will do, and the height and width of the rectangle.</p> <blockquote><blockquote><blockquote><p>we assume it is not rotated relative to the X and Y axes </p> </blockquote></blockquote><p>Ehh??? Do not understand what is being said and am not certain it needs to be said. </p> &#8212; maddalab (2009-07-26 07:36:56) </blockquote> </div>urn:uuid:50f0c210-64f6-3419-83c2-b957124e7869maddalab2009-07-26T07:36:56-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_body_of_point_defines_on">The body of <code class="literal">Point</code> defines one method, an <span class="emphasis"><em>override</em></span> of the familiar <code class="literal">toString</code> method in Java (like <code class="literal">ToString</code> in C#). Note that Scala, like C#, requires the <code class="literal">override</code> keyword whenever you override a concrete method. Unlike C#, you don&#8217;t have to use a <code class="literal">virtual</code> keyword on the original concrete method. In fact, there is no <code class="literal">virtual</code> keyword in Scala. As before, we omit the curly braces "{&#8230;}" around the body of <code class="literal">toString</code>, since it has only one expression.</p> <blockquote><p>Not certain about this, however I also omit the () braces around methods with no args along with the {} braces as it enforces the uniform access principle in Scala. Clients of the code do not need to know that they are invoking a function or accessing a member </p> <p>override def toString() = "Point(" + x + "," + y + ")" </p> <p>would becode </p> <p>override def toString = "Point(" + x + "," + y + ")" </p> <p>not certain about its applicability to methods defined in the Java API being overridden in Scala. </p> &#8212; maddalab (2009-07-26 07:34:03) </blockquote> </div>urn:uuid:5e0406c4-d2d0-3898-99b5-25f544a63d79maddalab2009-07-26T07:34:03-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_shape_class_hierarchy_is">The <code class="literal">Shape</code> class hierarchy is defined in a <code class="literal">shapes</code> package. You can declare the package using Java syntax, but Scala also supports a syntax similar to C#'s &#8220;namespace&#8221; syntax, where the entire declaration is scoped using curly braces, as used here. The Java-style package declaration syntax is far more commonly used, however, being both compact and readable.</p> <blockquote><p>Thought I would add that up until this point in the samples, it is possible to use the Scala REPL, which I find convenient. However with the introduction of packages it would not be possible to use the REPL as the REPL does not support packages. Might be worth noting for readers like me who type packages in the REPL. </p> &#8212; maddalab (2009-07-26 07:27:58) </blockquote> </div>urn:uuid:109198e9-e3fc-39af-aff0-5fd5f125fecdmaddalab2009-07-26T07:27:58-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_now_the_upper_method_has_bee">Now the <code class="literal">upper</code> method has been renamed <code class="literal">main</code>. Because <code class="literal">Upper</code> is an <code class="literal">object</code>, this <code class="literal">main</code> method works exactly like a <code class="literal">static main</code> method in a Java class. It is the entry point to the <code class="literal">Upper</code> <span class="emphasis"><em>application</em></span>.</p> <blockquote><p>In the example I believe it is good scala convention to omit the '=' sign as the main method finished with a println, i.e. has result type Unit (would be the same if println was omitted as foreach has a result type of Unit) </p> <p>The convention is used to indicate "procedural" (relies on side effects, printf) behavior of main </p> &#8212; maddalab (2009-07-26 06:12:25) </blockquote> </div>urn:uuid:b6667866-59bf-3e47-9948-47f49bbd543dmaddalab2009-07-26T06:12:25-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_the_implementation_of_upper_">The implementation of <code class="literal">upper</code> on the second line is also simpler. Scala can usually infer the return type of the method (but not the types of the method arguments), so we drop the explicit declaration. Also, because there is only one expression in the method body, we drop the braces and put the entire method definition on one line. The equals sign before the method body tells the compiler, as well as the human reader, where the method body begins.</p> <blockquote><blockquote><blockquote><p>The equals sign before the method body tells the compiler, as well as the human reader, where the method body begins. </p> </blockquote></blockquote><p>Is this redundant, and possibly misleading? You already have a must better reason for the equals sign previously when you say </p> <p>"Using an equals sign also reminds us that even functions are values in Scala, which is consistent with Scala’s support of functional programming" </p> &#8212; maddalab (2009-07-26 05:52:44) </blockquote> </div>urn:uuid:0fd50fb5-bc9f-310b-a7e2-8d06a8b8cc52maddalab2009-07-26T05:52:44-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_note_that_this_code_is_fully_t">Note that this code is fully thread safe. We don&#8217;t declare any variables that might cause thread-safety issues. The API methods we use are also thread-safe. Therefore, we don&#8217;t need multiple instances. A singleton <code class="literal">object</code> works fine.</p> <blockquote><p>Just a comment on the comment. ;) </p> <p>I did not understand what was being said, until I read Bruce Leidl's comment about scala singletons not have concurrency considerations that you would have when implementing the same in Java. </p> &#8212; maddalab (2009-07-26 05:49:53) </blockquote> </div>urn:uuid:67990f54-720f-337b-95d7-14f5c5e0ceedmaddalab2009-07-26T05:49:53-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_the_method_body_calls_the_map">The method body calls the <code class="literal">map</code> method on the <code class="literal">strings</code> array, which takes a <span class="emphasis"><em>function literal</em></span> as an argument. Function literals are &#8220;anonymous&#8221; functions. They are similar to <span class="emphasis"><em>lambdas</em></span>, <span class="emphasis"><em>closures</em></span>, <span class="emphasis"><em>blocks</em></span>, or <span class="emphasis"><em>procs</em></span> in other languages. In Java, you would have to use an anonymous inner class here that implements a method defined by an interface, <span class="emphasis"><em>etc.</em></span></p> <blockquote><p>I understand function literals as syntactic sugar. Function literal syntax can be used to code either anonymous functions (do not capture variables in scope, as in the example here, lambdas) or closures. </p> <p>This is the first time I have read function literals being directly referenced as functions (albeit anonymous). </p> <p>Nitpicking may be, and I am not certain what is a better approach for someone reading on scala for the first time </p> &#8212; maddalab (2009-07-26 05:43:30) </blockquote> </div>urn:uuid:1d9cb493-09ca-3904-8acd-87738e279afcmaddalab2009-07-26T05:43:30-07:00Comment on 'A Taste of Scala' <div>Why Scala? <dt id="varlistentry-statically-typed"><span class="term"> Statically Typed </span></dt> <blockquote><p>Surprised you did no mention type inference here (or any of the sub-sections below). Isn't Scala also one of the few "type-inferenced" languages on the JVM? </p> &#8212; maddalab (2009-07-26 05:07:41) </blockquote> </div>urn:uuid:324efe09-d140-3359-9344-eb940c6f32c5maddalab2009-07-26T05:07:41-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_when_using_a_static_language_">When using a static language, you have to think about appropriate type choices more often, which forces you to weigh design choices more carefully. While this may slow down daily design decisions, thinking through the types in the application can result in a more coherent design over time.</p> <blockquote><p>As you mentioned previously pro and cons of static and dynamic typing are subjective, but this paragraph is a flame bait </p> <p>"forces you to weigh design choices more carefully." </p> <p>Caring about your craft forces you to weigh design choices more carefully and lead to coherent design over time. </p> <p>I have seen plenty of code in Java that returns Object and invokes methods using reflection over the returned typed. What was needed was an interface that all the returned types returned. Static typing does not by itself lead to better design. </p> &#8212; maddalab (2009-07-26 04:53:24) </blockquote> </div>urn:uuid:47eec2a3-e111-39ef-8b88-cad312b9c70bmaddalab2009-07-26T04:53:24-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_the_never_ending_need_to_scale">The never-ending need to scale is driving architectures towards pervasive concurrency. However, Java&#8217;s concurrency model, which is based on synchronized access to shared, mutable state, results in complex and error-prone programs.</p> <blockquote><p>Just a comment on the writing, this line is difficult to understand </p> <p>The never-ending need to scale is driving architectures towards pervasive concurrency. </p> <p>I think you meant the following The never-ending need to scale "software" is driving "application" architectures towards pervasive concurrency. </p> <p>and I would rather like The never-ending need to scale software is driving application developers towards concurrent architectures. </p> <p>scale Hardware/Software? architectures Hardware/Software/ </p> <p>Am I to read the original line as </p> <p>The never-ending need to scale software is driving software architectures towards pervasive concurrency. </p> <p>The never-ending need to scale software is driving hardware architectures towards pervasive concurrency. </p> <p>The never-ending need to scale hardware is driving hardware architectures towards pervasive concurrency. </p> <p>or one of the alternatives </p> &#8212; maddalab (2009-07-26 04:08:56) </blockquote> </div>urn:uuid:14fa3480-d26d-3bec-95b5-75a56429583fmaddalab2009-07-26T04:08:56-07:00Comment on 'Why Scala?' <div>A Taste of Concurrency <p id="para_now_that_we_have_defined_our_s">Now that we have defined our shapes types, let&#8217;s return to actors. We define an <code class="literal">Actor</code> that receives &#8220;messages&#8221; that are shapes to draw.</p> <blockquote><p>Not my intention. Rather I was talking "up" to them, because most experienced devs. would implement this separation of concerns and I want them to know we'll learn techniques for doing that later on. </p> &#8212; deanwampler (2009-07-12 18:22:16) </blockquote> </div>urn:uuid:d9a547b8-a40d-3826-a77a-dde8e708d3cedeanwampler2009-07-12T18:22:16-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_in_this_case_shape_declares_a">In this case, Shape declares an <span class="emphasis"><em>abstract</em></span> <code class="literal">draw</code> method. We know it is abstract because it has no body. No <code class="literal">abstract</code> keyword is required on the method. Abstract methods in Scala are just like abstract methods in Java and C#. (See <a class="xref" href="ch06.html#OverridingMembers" title="Overriding Members of Classes and Traits">the section called &#8220;Overriding Members of Classes and Traits&#8221;</a> in <a class="xref" href="ch06.html" title="Chapter&#160;6.&#160;Advanced Object-Oriented Programming In Scala">Chapter&#160;6, <i>Advanced Object-Oriented Programming In Scala</i></a> for more details.)</p> <blockquote><p>Thanks. Oversight. Will fix. </p> &#8212; deanwampler (2009-07-12 18:13:33) </blockquote> </div>urn:uuid:02606463-5af5-38ed-a7c3-d8dca7d2b274deanwampler2009-07-12T18:13:33-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_shape_class_hierarchy_is">The <code class="literal">Shape</code> class hierarchy is defined in a <code class="literal">shapes</code> package. You can declare the package using Java syntax, but Scala also supports a syntax similar to C#'s &#8220;namespace&#8221; syntax, where the entire declaration is scoped using curly braces, as used here. The Java-style package declaration syntax is far more commonly used, however, being both compact and readable.</p> <blockquote><p>Good catch. Thanks. Will fix. </p> &#8212; deanwampler (2009-07-12 18:12:25) </blockquote> </div>urn:uuid:f045bd9f-aa06-3b7d-838a-b7f6be2178d7deanwampler2009-07-12T18:12:25-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_shape_class_hierarchy_is">The <code class="literal">Shape</code> class hierarchy is defined in a <code class="literal">shapes</code> package. You can declare the package using Java syntax, but Scala also supports a syntax similar to C#'s &#8220;namespace&#8221; syntax, where the entire declaration is scoped using curly braces, as used here. The Java-style package declaration syntax is far more commonly used, however, being both compact and readable.</p> <blockquote><p>Circle and Rectangle extend Shape, but Triangle extends Shape(). If this wasn't intentional, it might confuse readers. </p> &#8212; jwolski (2009-07-11 07:43:46) </blockquote> </div>urn:uuid:696e36c6-5ea1-3464-ad59-27993b620ddejwolski2009-07-11T07:43:46-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_recall_that_we_declared_draw_">Recall that we declared <code class="literal">draw</code> as an abstract method in <code class="literal">Shape</code> and we implemented <code class="literal">draw</code> in the concrete subclasses. Hence, the code in the first <code class="literal">case</code> statement invokes a polymorphic operation.</p> <blockquote><p>Thanks. We fixed that one ;) </p> &#8212; deanwampler (2009-07-09 15:38:44) </blockquote> </div>urn:uuid:f961d9bc-76a5-3201-8e89-9428563a6e0adeanwampler2009-07-09T15:38:44-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_to_run_this_script_go_to_a_co">To run this script, go to a command window, change to the same directory and run the following command.</p> <blockquote><p>@Geoffrey, I didn't try it any of the IDEs. We tried to avoid any dependencies on using them. </p> &#8212; deanwampler (2009-07-09 15:34:49) </blockquote> </div>urn:uuid:0148546c-be1c-3d21-b6ec-bc25b86a75cddeanwampler2009-07-09T15:34:49-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_an_alternative_strategy_is_to_">An alternative strategy is to combine several, simpler languages, <span class="emphasis"><em>e.g.</em></span>, Java for object-oriented code and Erlang for functional, concurrent code. Such a decomposition can work, but only if your system decomposes cleanly into such discrete parts and your team can manage a heterogeneous environment. Scala is attractive for situations where a single, all-in-one language is preferred. That said, Scala code can happily coexist with other languages, especially on the JVM or .NET.</p> <blockquote><p>You may want to point out that using Java and Erlang for the same project is most likely a poor alternative to using Java and/or Scala on their own. E.g. how would a Java class/component call an Erlang method (i.e. integration issues)? </p> <p>This is the advantage of using Groovy or Scala (or other JVM-compatible languages) for integration with existing JEE or .NET systems. </p> &#8212; asookazian (2009-07-08 14:29:10) </blockquote> </div>urn:uuid:328cf77b-384c-3872-aa74-817d274c7861asookazian2009-07-08T14:29:10-07:00Comment on 'Why Scala?' <div>A Taste of Scala <p id="para_takes_a_single_string_argume">It takes an argument list with a single <code class="literal">String</code> argument named <code class="literal">s</code>. The body of the function literal is after the &#8220;arrow&#8221;, <code class="literal">=&gt;</code>. It calls <code class="literal">toUpperCase()</code> on <code class="literal">s</code>. The result of this call is returned by the function literal. In Scala, the last <span class="emphasis"><em>expression</em></span> in a function is the return value, although you can have <code class="literal">return</code> statements elsewhere, too. The <code class="literal">return</code> keyword is optional here and it is rarely used, except when returning out of the middle of a block (<span class="emphasis"><em>e.g.,</em></span> in an <code class="literal">if</code> statement).</p> <blockquote><p>"=&gt;" suggests a function mapping. In this case, the function maps from the set of all strings to the set of upper case strings. "=" implies that the set of all strings is equivalent to the set of upper case strings, which obviously is not true. So, I think the choice of "=&gt;" over "=" is appropriate. </p> &#8212; derekmahar (2009-07-08 14:16:24) </blockquote> </div>urn:uuid:d4b19337-fb0e-37e4-8855-91803e494d01derekmahar2009-07-08T14:16:24-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_developers_want_languages_that">Developers want languages that are more succinct and flexible to improve their productivity. This is one reason why so-called &#8220;scripting&#8221; languages like Ruby and Python have become more popular recently.</p> <blockquote><p>what about Groovy? we can use Groovy in Seam apps... </p> <p>"I can honestly say if someone had shown me the Programming Scala book by by Martin Odersky, Lex Spoon &amp; Bill Venners back in 2003 I'd probably have never created Groovy." </p> <p>http://java.dzone.com/articles/scala-long-term-replacement </p> &#8212; asookazian (2009-07-08 14:11:34) </blockquote> </div>urn:uuid:28c1921d-17c7-324e-84de-c116f7705b27asookazian2009-07-08T14:11:34-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_why_scala2">To meet these challenges, many developers are looking for new languages and tools. Venerable standbys like Java, C#, and C++ are no longer optimal for developing the next generation of applications.</p> <blockquote><p>as I understand it, the significant advantage that Erlang and Scala offer over Java and C#, for example, are concurrent programming for use in multi-core envmts. And Scala is even more attractive in a J2SE or J2EE platform because it runs in a JVM (compiles to Java bytecode). </p> <p>Microsoft .NET has just recently implemented the MVC design pattern in ASP.NET: </p> <p>http://weblogs.asp.net/scottgu/archive/2008/07/14/asp-net-mvc-preview-4-release-part-1.aspx </p> <p>In many ways, .NET is far behind but traction in JEE frameworks other than Spring and Hibnerate (e.g. Seam 2.x) is very low and EE 6 with Web Beans may not have a high adoption rate in the enterprise deployments either... </p> &#8212; asookazian (2009-07-08 14:07:08) </blockquote> </div>urn:uuid:b5cdef42-fe89-36b4-a6d4-26fc4edac6c7asookazian2009-07-08T14:07:08-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_despite_their_productivity_adv">Despite their productivity advantages, <span class="emphasis"><em>dynamic</em></span> languages may not be the best choices for all applications, particularly for very large code bases and high-performance applications. There is a longstanding, spirited debate in the programming community about the relative merits of dynamic <span class="emphasis"><em>vs.</em></span> static typing. Many of the points of comparison are somewhat subjective. We won&#8217;t go through all the arguments here, but we will offer a few thoughts for consideration.</p> <blockquote><p>Given the headings, a Java programmer may skip this section thinking that it is not relevant to them. If they do, they will miss the whole Static vs Dynamic discussion. </p> &#8212; gedb (2009-07-08 06:25:02) </blockquote> </div>urn:uuid:ec51b2c5-414e-32cd-a8d9-c2bd812b9609gedb2009-07-08T06:25:02-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_scala_is_a_language_for__profe">Scala is a language for <span class="emphasis"><em>professional</em></span> developers. Compared to languages like Java and Ruby, Scala is a more difficult language to master, because it requires competency with OOP, FP, and static typing to use it most effectively. It is tempting to prefer the relative simplicity of dynamically-typed languages. Yet, this simplicity can be deceptive. In a dynamically typed language, it is often necessary to use metaprogramming features to implement advanced designs. While metaprogramming is powerful, using it well takes experience and the resulting code tends to be hard to understand, maintain, and debug. In Scala, many of the same design goals can be achieved in a type-safe manner by exploiting its type system and mixin composition through <span class="emphasis"><em>traits</em></span>.</p> <blockquote><p>Put a different way: how do you measure the level of difficulty of a programming language and how this may translate to programmer productivity or suitability to solve particular problems? Experience? Empirical evidence? Anecdotal evidence? Programmer surveys? Programming language popularity? </p> <p>Unfortunately, programming language choice seems largely driven by familiarity, popularity, and perceived ease of learning rather than by suitability to task and longer term program maintainability. </p> &#8212; derekmahar (2009-07-07 11:02:59) </blockquote> </div>urn:uuid:3dbdeaa7-7d69-3082-bc9c-f65247961287derekmahar2009-07-07T11:02:59-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_scala_is_compelling_because_it">Scala is compelling because it feels like a dynamically typed scripting language, due to its succinct syntax and type inference. Yet, Scala gives you all the benefits of static typing, a modern object model, functional programming, and an advanced type system. These tools let you build scalable, modular applications that can reuse legacy Java and .NET APIs and leverage the performance of the JVM and CLR.</p> <blockquote><p>Scala is succinct relative to Java. Which ML languages run on the JVM? Is Clojure, a LISP dialect for the JVM, more concise than Scala? </p> &#8212; derekmahar (2009-07-07 10:04:55) </blockquote> </div>urn:uuid:a8ce63dc-f6da-3e16-a380-e965d1d6f3f0derekmahar2009-07-07T10:04:55-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_scala_was_started_by_martin_od">Scala was started by Martin Odersky in 2001. Martin is a professor in the School of Computer and Communication Sciences at the Ecole Polytechnique F&#233;d&#233;rale de Lausanne (EPFL). He spent his graduate years working in the group headed by Niklaus Wirth, of Pascal fame. Martin worked on Pizza, an early functional language on the JVM. He later worked on GJ, a prototype of what later became Generics in Java, with Philip Wadler of Haskell fame. Martin was hired by Sun Microsystems to produce the reference implementation of <strong class="userinput"><code>javac</code></strong>, the Java compiler that ships with the Java Developer Kit (JDK) today.</p> <blockquote><p>Favour active over passive voice: change "Scala was started by Martin Odersky in 2001" to "Martin Odersky started Scala in 2001". </p> &#8212; derekmahar (2009-07-07 09:57:51) </blockquote> </div>urn:uuid:b4d56d18-071f-3207-800c-14b1c384d9d6derekmahar2009-07-07T09:57:51-07:00Comment on 'Why Scala?' <div>Why Scala? <dt id="varlistentry-statically-typed"><span class="term"> Statically Typed </span></dt> <blockquote><p>Statically typed languages also bind a type to every value (or object). Otherwise, polymorphism through dynamic binding would not be possible. </p> &#8212; derekmahar (2009-07-06 15:06:14) </blockquote> </div>urn:uuid:c95394ae-d950-3e22-ba83-d6da7eb82f4bderekmahar2009-07-06T15:06:14-07:00Comment on 'Why Scala?' <div>A Taste of Scala <p id="para_to_be_clear_these_two_uses_of">To be clear, these two uses of &#8216;_&#8217; are completely independent of each other. Method chaining and function-literal shorthands, as in this example, can take some getting used to, but once you are comfortable with them, they yield very readable code with minimal use of temporary variables.</p> <blockquote><p>It is difficult to tell that the character before the underscore here is a comma, not a period. Perhaps it should be mentioned explicitly in the text. As well, function parameters are usually separated using a comma and a space, so the curried function here would appear better as: </p> <pre><code>printf("%s ", _) </code></pre><p>An off-hand reference to the arguments could include the word comma to differentiate this from the _.functionName syntax above: "Here the underscore is given as the second parameter of the function, separated from the print format string by a comma, as usual." </p> &#8212; TimMacEachern (2009-06-23 08:32:57) </blockquote> </div>urn:uuid:89056fe9-81ad-39e2-8841-3ef741575621TimMacEachern2009-06-23T08:32:57-07:00Comment on 'A Taste of Scala' <div>A Taste of Concurrency <p id="para_now_that_we_have_defined_our_s">Now that we have defined our shapes types, let&#8217;s return to actors. We define an <code class="literal">Actor</code> that receives &#8220;messages&#8221; that are shapes to draw.</p> <blockquote><p>In "Of course, in a real..." you're talking down to your readers. There's no need for that, certainly at the start of the book. Just drop the "Of course". </p> &#8212; TimMacEachern (2009-06-23 07:42:58) </blockquote> </div>urn:uuid:e6db0c79-3ffe-3e07-a11d-b247942f5204TimMacEachern2009-06-23T07:42:58-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_first_case_does_a_type_c">The first <code class="literal">case</code> does a type comparison with the message. (There is no explicit variable for the message instance in the code; it is inferred.) If the message is of type <code class="literal">Shape</code>, the first <code class="literal">case</code> matches. The message instance is cast to a <code class="literal">Shape</code> and assigned to the variable <code class="literal">s</code>, then the <code class="literal">draw</code> method is called on it.</p> <blockquote><p>A reference to a section that talks about how this inferrence works would be useful; I'm curious, but I've got no link to click. </p> &#8212; diathesis (2009-06-22 13:56:54) </blockquote> </div>urn:uuid:7e1999ed-d401-3bfd-ac29-c81544f1765adiathesis2009-06-22T13:56:54-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_to_run_this_script_go_to_a_co">To run this script, go to a command window, change to the same directory and run the following command.</p> <blockquote><p>This example doesn't seem to work in the current Eclipse IDE; it's fine at the command-line, but shows that the IDE support is still suspect. :/ </p> &#8212; diathesis (2009-06-20 21:09:34) </blockquote> </div>urn:uuid:c1c88a55-3d5b-323c-9e9f-e8603219832ddiathesis2009-06-20T21:09:34-07:00Comment on 'A Taste of Scala' <div>A Taste of Concurrency <p id="para_the_last_case_handles_any_ot">The last <code class="literal">case</code> clause handles any other message instance, thereby functioning as the <span class="emphasis"><em>default</em></span> case. The actor reports an error and then drops the message. <code class="literal">Any</code> is the parent of all types in the Scala type hierarchy, like <code class="literal">Object</code> is the root type in Java and other languages. Hence, this case clause will match any message of any type. Pattern matching is eager; we have to put this case clause at the end, so it doesn&#8217;t consume the messages we are expecting!</p> <blockquote><p>Okay, no you don't mean that. But maybe you could emphasize 'at the end' a bit more, and point out that unexpected messages would still be consumed (but silently) if it wasn't included. </p> &#8212; robcd (2009-06-20 09:57:37) </blockquote> </div>urn:uuid:45863ce7-2736-3227-a2ca-92af1c14dac1robcd2009-06-20T09:57:37-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_last_case_handles_any_ot">The last <code class="literal">case</code> clause handles any other message instance, thereby functioning as the <span class="emphasis"><em>default</em></span> case. The actor reports an error and then drops the message. <code class="literal">Any</code> is the parent of all types in the Scala type hierarchy, like <code class="literal">Object</code> is the root type in Java and other languages. Hence, this case clause will match any message of any type. Pattern matching is eager; we have to put this case clause at the end, so it doesn&#8217;t consume the messages we are expecting!</p> <blockquote><p>Don't you mean, '<em>if we don't want it to silently</em> consume the messages we <em>aren't</em> expecting'? </p> &#8212; robcd (2009-06-20 05:05:53) </blockquote> </div>urn:uuid:202d37f2-abf5-3df1-9ff3-eaa75adc21carobcd2009-06-20T05:05:53-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_the_first_line_inside_the_mai">The first line inside the <code class="literal">main</code> method uses the same short-hand notation for <code class="literal">map</code> that we just examined.</p> <blockquote><p>Note .. main must be a <em>(possibly inherited)</em> method in an object? </p> &#8212; robcd (2009-06-20 03:57:29) </blockquote> </div>urn:uuid:95b49ff5-492b-399c-8e6b-449266326201robcd2009-06-20T03:57:29-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_the_method_return_type_appears">The method return type appears after the argument list. In this case, the return type is <code class="literal">Seq[String]</code>, where <code class="literal">Seq</code> ("sequence") is a particular kind of collection. It is a <span class="emphasis"><em>parameterized type</em></span> (like a <span class="emphasis"><em>generic</em></span> type in Java), parameterized here with <code class="literal">String</code>. Note that Scala uses square brackets <code class="literal">[&#8230;]</code> for parameterized types, while Java uses angle brackets <code class="literal">&lt;&#8230;&gt;</code>.</p> <blockquote><ul> <li> Note ... when you omit the colon </li> <li> Note ... than when you omit the colon </li> </ul> &#8212; robcd (2009-06-20 03:34:48) </blockquote> </div>urn:uuid:1b98a2bc-6aa2-3912-be95-acd7108b347crobcd2009-06-20T03:34:48-07:00Comment on 'A Taste of Scala' <div>Why Scala? <dt id="varlistentry-mixed-paradigm-object-oriented-programming"><span class="term"> Mixed Paradigm - Object Oriented Programming </span></dt> <blockquote><p>As a Java programmer, I don't find the idea of unifying interfaces with implementations to be an illuminating metaphor. It just makes traits sound like classes. Mixin is a clearer term, as is the reference to Ruby modules. </p> &#8212; diathesis (2009-06-19 19:13:08) </blockquote> </div>urn:uuid:f4dcca01-2b6b-3338-832f-2442b9fff8cediathesis2009-06-19T19:13:08-07:00Comment on 'Why Scala?' <div>A Taste of Concurrency <p id="para_in_this_case_shape_declares_a">In this case, Shape declares an <span class="emphasis"><em>abstract</em></span> <code class="literal">draw</code> method. We know it is abstract because it has no body. No <code class="literal">abstract</code> keyword is required on the method. Abstract methods in Scala are just like abstract methods in Java and C#. (See <a class="xref" href="ch06.html#OverridingMembers" title="Overriding Members of Classes and Traits">the section called &#8220;Overriding Members of Classes and Traits&#8221;</a> in <a class="xref" href="ch06.html" title="Chapter&#160;6.&#160;Advanced Object-Oriented Programming In Scala">Chapter&#160;6, <i>Advanced Object-Oriented Programming In Scala</i></a> for more details.)</p> <blockquote><p>Maybe a quick explanation of "Unit" here? </p> &#8212; bfollek (2009-06-19 06:02:01) </blockquote> </div>urn:uuid:4f2f118c-57e1-31f7-9e96-2bbb9e66ca42bfollek2009-06-19T06:02:01-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_takes_a_single_string_argume">It takes an argument list with a single <code class="literal">String</code> argument named <code class="literal">s</code>. The body of the function literal is after the &#8220;arrow&#8221;, <code class="literal">=&gt;</code>. It calls <code class="literal">toUpperCase()</code> on <code class="literal">s</code>. The result of this call is returned by the function literal. In Scala, the last <span class="emphasis"><em>expression</em></span> in a function is the return value, although you can have <code class="literal">return</code> statements elsewhere, too. The <code class="literal">return</code> keyword is optional here and it is rarely used, except when returning out of the middle of a block (<span class="emphasis"><em>e.g.,</em></span> in an <code class="literal">if</code> statement).</p> <blockquote><p>I know that you don't want to add any further details into this introduction, so I'm writing this comment with that in mind. For some perspective, I'm fairly new to Scala, coming to this book after a plethora of assorted blog posts and tutorials. </p> <p>As someone who is familiar with Ruby, I'm a bit more interested in why =&gt; is used rather than =, and not so much in the fact that the last value of a function is the implicit return value. I think both should be mentioned, but even after reading lots of introductory information, the =/=&gt; distinction still confuses me. Maybe a bit less real-estate for return and a bit more to explain =&gt; quickly? </p> &#8212; nolan (2009-06-12 18:54:58) </blockquote> </div>urn:uuid:468a72ca-5d44-3e8c-b758-e8763f52d5b7nolan2009-06-12T18:54:58-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_we_feel_that_the_extra_effort_">We feel that the extra effort required day to day to use Scala will promote more careful reflection about your designs. Over time, this discipline will yield more coherent, modular, and maintainable applications. Fortunately, you don&#8217;t need all of the sophistication of Scala all of the time. Much of your code will have the simplicity and clarity of code written in your favorite dynamically-typed language.</p> <blockquote><p>Ah, by "extra effort" do you mean proper design to begin with? </p> &#8212; psalvitti (2009-06-06 21:21:52) </blockquote> </div>urn:uuid:d66ed27a-81f0-352b-af9c-0a1f061c651epsalvitti2009-06-06T21:21:52-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_scala_is_a_language_for__profe">Scala is a language for <span class="emphasis"><em>professional</em></span> developers. Compared to languages like Java and Ruby, Scala is a more difficult language to master, because it requires competency with OOP, FP, and static typing to use it most effectively. It is tempting to prefer the relative simplicity of dynamically-typed languages. Yet, this simplicity can be deceptive. In a dynamically typed language, it is often necessary to use metaprogramming features to implement advanced designs. While metaprogramming is powerful, using it well takes experience and the resulting code tends to be hard to understand, maintain, and debug. In Scala, many of the same design goals can be achieved in a type-safe manner by exploiting its type system and mixin composition through <span class="emphasis"><em>traits</em></span>.</p> <blockquote><p>I might tone this down a bit ... I mean comparatively speaking, C++, Java, Ruby, et al (statically typed languages) all require competency in OOP, FP and static typing that you indicate for Scala. As Henrik said, what does "mastering" really mean? I can point to "experienced" developers (name the language) that still write horrible code. </p> &#8212; psalvitti (2009-06-06 21:20:38) </blockquote> </div>urn:uuid:f4933c2f-20fc-3b3f-be4c-22e3ebc67a5dpsalvitti2009-06-06T21:20:38-07:00Comment on 'Why Scala?' <div>A Taste of Concurrency <p id="para_five_messages_are_sent_to_the_">Five messages are sent to the actor, using the syntax <code class="literal">actor ! message</code>. The first message sends a <code class="literal">Circle</code> instance. The actor &#8220;draws&#8221; the circle. The second message sends a <code class="literal">Rectangle</code> message. The actor &#8220;draws&#8221; the rectangle. The third message does the same thing for a <code class="literal">Triangle</code>. The fourth message sends a <code class="literal">Double</code> that is approximately equal to <span class="emphasis"><em>Pi</em></span>. This is an unknown message for the actor, so it just prints an error message. The final message sends an &#8220;exit&#8221; string, which causes the actor to terminate.</p> <blockquote><p>Thanks! </p> &#8212; deanwampler (2009-06-03 08:25:55) </blockquote> </div>urn:uuid:e14c557b-5670-3257-93d2-2fcc5482fa78deanwampler2009-06-03T08:25:55-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_all_the_methods_and_public_fie">All the methods and public fields from <code class="literal">Actor</code> are imported. These are not <code class="literal">static</code> imports from the <code class="literal">Actor</code> type, as they would be in Java. Rather, they are imported from an <code class="literal">object</code> that is also named <code class="literal">Actor</code>. The <code class="literal">class</code> and <code class="literal">object</code> can have the same name, as we will see in <a class="xref" href="ch06.html#CompanionObjects" title="Companion Objects">the section called &#8220;Companion Objects&#8221;</a> in <a class="xref" href="ch06.html" title="Chapter&#160;6.&#160;Advanced Object-Oriented Programming In Scala">Chapter&#160;6, <i>Advanced Object-Oriented Programming In Scala</i></a>.</p> <blockquote><p>Missing links now fixed. </p> &#8212; deanwampler (2009-06-03 08:24:00) </blockquote> </div>urn:uuid:690cc7dc-3c6f-3383-9fb0-8e8cecb1fc0cdeanwampler2009-06-03T08:24:00-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_the_point_class_represents_a">The <code class="literal">Point</code> class represents a two-dimensional point on a plane. Note the argument list after the class name. Those are constructor parameters. In Scala, the <span class="emphasis"><em>whole</em></span> class body is the constructor, so you list the arguments for the <span class="emphasis"><em>primary</em></span> constructor after the class name and before the class body. (We&#8217;ll see how to define auxiliary constructors in <a class="xref" href="ch05.html#Constructors" title="Constructors in Scala">the section called &#8220;Constructors in Scala&#8221;</a> in <a class="xref" href="ch05.html" title="Chapter&#160;5.&#160;Basic Object-Oriented Programming in Scala">Chapter&#160;5, <i>Basic Object-Oriented Programming in Scala</i></a>.) Because we put the <code class="literal">val</code> keyword before each parameter declaration, they are automatically converted to read-only fields with the same names with public reader methods of the same name. That is, when you instantiate a <code class="literal">Point</code> instance, <span class="emphasis"><em>e.g.</em></span>, <code class="literal">point</code>, you can read the fields using <code class="literal">point.x</code> and <code class="literal">point.y</code>. If you want <span class="emphasis"><em>mutable</em></span> fields, then use the keyword <code class="literal">var</code>. We&#8217;ll explore variable declarations and the <code class="literal">val</code> and <code class="literal">var</code> keywords in <a class="xref" href="ch02.html#VariableDeclarationsAndDefinitions" title="Variable Declarations">the section called &#8220;Variable Declarations&#8221;</a> in <a class="xref" href="ch02.html" title="Chapter&#160;2.&#160;Type Less, Do More">Chapter&#160;2, <i>Type Less, Do More</i></a>.</p> <blockquote><p>Another production problem that has since been fixed. Sorry. </p> &#8212; deanwampler (2009-06-03 08:23:36) </blockquote> </div>urn:uuid:a4dab6a3-0289-3ebc-8649-a0b2e6675eecdeanwampler2009-06-03T08:23:36-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_there_are_many_reasons_to_be_s">There are many reasons to be seduced by Scala. One reason is the <code class="literal">Actors</code> API included in the Scala library, which is based on the robust <code class="literal">Actors</code> concurrency model built into Erlang <a class="xref" href="apa.html#Haller2007">[Haller2007]</a>. Here is an example to whet your appetite.</p> <blockquote><p>Good points. Will fix. </p> &#8212; deanwampler (2009-06-03 08:20:46) </blockquote> </div>urn:uuid:c2973f65-e66b-3536-b38a-9f43bc09ed10deanwampler2009-06-03T08:20:46-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_the_cp_option_adds_he_cur">The <strong class="userinput"><code>-cp .</code></strong> option adds the current directory to the search &#8220;class path&#8221;. You should get the following output.</p> <blockquote><p>Thanks! Will fix </p> &#8212; deanwampler (2009-06-03 08:20:11) </blockquote> </div>urn:uuid:e0b5aa4a-1bd9-35f3-9217-41f9e68c7499deanwampler2009-06-03T08:20:11-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_note_that_this_code_is_fully_t">Note that this code is fully thread safe. We don&#8217;t declare any variables that might cause thread-safety issues. The API methods we use are also thread-safe. Therefore, we don&#8217;t need multiple instances. A singleton <code class="literal">object</code> works fine.</p> <blockquote><p>That's all I'm really saying. </p> &#8212; deanwampler (2009-06-03 08:12:01) </blockquote> </div>urn:uuid:7d8cae81-e262-3778-9fc3-1af873d203d8deanwampler2009-06-03T08:12:01-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_on_the_first_line_upper_is_">On the first line, <code class="literal">Upper</code> is now declared as an <code class="literal">object</code>, which is a <span class="emphasis"><em>singleton</em></span>. We are declaring a class, but the Scala runtime will only ever create one instance of <code class="literal">Upper</code>. (You can&#8217;t write <code class="literal">new Upper</code>, for example.) Scala uses <code class="literal">objects</code> for situations where other languages would use &#8220;class-level&#8221; members, like <code class="literal">statics</code> in Java. We don&#8217;t really need more than one <span class="emphasis"><em>instance</em></span> here, so a singleton is fine.</p> <blockquote><p>I'll drop the word "class" from "singleton class" and maybe add some more text. </p> &#8212; deanwampler (2009-06-03 08:08:54) </blockquote> </div>urn:uuid:33657b45-8cd6-373b-bb3e-1af48525db1ddeanwampler2009-06-03T08:08:54-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_takes_a_single_string_argume">It takes an argument list with a single <code class="literal">String</code> argument named <code class="literal">s</code>. The body of the function literal is after the &#8220;arrow&#8221;, <code class="literal">=&gt;</code>. It calls <code class="literal">toUpperCase()</code> on <code class="literal">s</code>. The result of this call is returned by the function literal. In Scala, the last <span class="emphasis"><em>expression</em></span> in a function is the return value, although you can have <code class="literal">return</code> statements elsewhere, too. The <code class="literal">return</code> keyword is optional here and it is rarely used, except when returning out of the middle of a block (<span class="emphasis"><em>e.g.,</em></span> in an <code class="literal">if</code> statement).</p> <blockquote><p>We cover this topic in the next chapter. I'd rather not go into more details (even a link...) in this cursory introduction. </p> &#8212; deanwampler (2009-06-03 08:06:48) </blockquote> </div>urn:uuid:9be50585-0eda-36fc-b5e6-f9d44b1475f7deanwampler2009-06-03T08:06:48-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_the_method_body_calls_the_map">The method body calls the <code class="literal">map</code> method on the <code class="literal">strings</code> array, which takes a <span class="emphasis"><em>function literal</em></span> as an argument. Function literals are &#8220;anonymous&#8221; functions. They are similar to <span class="emphasis"><em>lambdas</em></span>, <span class="emphasis"><em>closures</em></span>, <span class="emphasis"><em>blocks</em></span>, or <span class="emphasis"><em>procs</em></span> in other languages. In Java, you would have to use an anonymous inner class here that implements a method defined by an interface, <span class="emphasis"><em>etc.</em></span></p> <blockquote><p>Will do. Thanks. </p> &#8212; deanwampler (2009-06-03 08:02:58) </blockquote> </div>urn:uuid:9c0f6b97-c33d-3778-a58e-f0b3b373885ddeanwampler2009-06-03T08:02:58-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_let_s_examine_the_code_in_deta">Let&#8217;s examine the code in detail, so we can begin to learn Scala syntax. There are a lot of details in just six lines of code! We&#8217;ll explain the general ideas here. All the ideas used in this example will be explained more thoroughly in later sections of the book.</p> <blockquote><p>Yea, I know... Always a struggle to decide how much really needs to be said... </p> &#8212; deanwampler (2009-06-03 08:02:21) </blockquote> </div>urn:uuid:19c55cca-5b9e-3a30-875e-629146895366deanwampler2009-06-03T08:02:21-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_in_this_example_the_upper_m">In this example, the <code class="literal">upper</code> method in the <code class="literal">Upper</code> class (no pun intended) converts the input strings to upper case and returns them in an array. The last line in the example converts four strings and prints the resulting Array.</p> <blockquote><p>I don't see it, but it might have been a production error where the "Command Line Tools" link disappeared in a prior build of the book. If you are STILL seeing this, could be a browser issue. Let us know with a new comment. </p> &#8212; deanwampler (2009-06-03 08:01:42) </blockquote> </div>urn:uuid:e9047d3e-dbea-3bc5-a12e-d29f18f54cf2deanwampler2009-06-03T08:01:42-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_scala_is_a_language_for__profe">Scala is a language for <span class="emphasis"><em>professional</em></span> developers. Compared to languages like Java and Ruby, Scala is a more difficult language to master, because it requires competency with OOP, FP, and static typing to use it most effectively. It is tempting to prefer the relative simplicity of dynamically-typed languages. Yet, this simplicity can be deceptive. In a dynamically typed language, it is often necessary to use metaprogramming features to implement advanced designs. While metaprogramming is powerful, using it well takes experience and the resulting code tends to be hard to understand, maintain, and debug. In Scala, many of the same design goals can be achieved in a type-safe manner by exploiting its type system and mixin composition through <span class="emphasis"><em>traits</em></span>.</p> <blockquote><p>Both Scala and metaprogramming like in Ruby take time to master. Assuming equal teams of "experts", I'm asserting that Scala code will be easier to maintain and evolve over the long-term than roughly-equivalent ruby metaprogramming code. That's my gut feeling... </p> &#8212; deanwampler (2009-06-03 07:58:36) </blockquote> </div>urn:uuid:76c8b591-3f62-32db-9588-1d01c0762a81deanwampler2009-06-03T07:58:36-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_the_name__scala__is_a_contract">The name <span class="emphasis"><em>Scala</em></span> is a contraction of the words <span class="emphasis"><em>scalable language</em></span>. While this suggests that the pronunciation should be <span class="emphasis"><em>scale-ah</em></span>, the creators of Scala actually pronounce it <span class="emphasis"><em>scah-lah</em></span>, like the Italian word for &#8220;stairs&#8221;. That is, the two &#8220;a&#8217;s&#8221; are pronounced the same.</p> <blockquote><p>Not sure where to discuss it either. I guess the "default" answer is that Scala fills the same niche as Java, C#, etc. while perhaps also covering some territory for which a "pure" scripting language like Ruby would be an optimal fit. </p> &#8212; deanwampler (2009-06-03 07:51:27) </blockquote> </div>urn:uuid:b166e59a-1c40-35e9-b1af-5ba315dff317deanwampler2009-06-03T07:51:27-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_it_might_appear_that_oop_and_f">It might appear that OOP and FP are incompatible. In fact, a design philosophy of Scala is that OOP and FP are more synergistic than opposed. The features of one approach can enhance the other.</p> <blockquote><p>@Marek. Good point. We cover this later in the book, but I'll add a paragraph about it here. </p> <p>@Ricky, I'll clarify to say one of the "few"... </p> <p>@Henrik, I'll add a disclaimer that there can be areas where performance is poor. </p> &#8212; deanwampler (2009-06-03 07:46:44) </blockquote> </div>urn:uuid:758188ee-9212-3e0a-8110-c834023a3044deanwampler2009-06-03T07:46:44-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_the_never_ending_need_to_scale">The never-ending need to scale is driving architectures towards pervasive concurrency. However, Java&#8217;s concurrency model, which is based on synchronized access to shared, mutable state, results in complex and error-prone programs.</p> <blockquote><p>I think we'll see clojure style mutability approaches, like STM, work their way back into Scala and maybe even Java, as options. </p> &#8212; deanwampler (2009-06-03 07:35:12) </blockquote> </div>urn:uuid:195d4f32-0eeb-3556-97c3-d1e502977929deanwampler2009-06-03T07:35:12-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_developers_want_languages_that">Developers want languages that are more succinct and flexible to improve their productivity. This is one reason why so-called &#8220;scripting&#8221; languages like Ruby and Python have become more popular recently.</p> <blockquote><p>Will make this statement more 'inclusive". </p> &#8212; deanwampler (2009-06-03 07:31:28) </blockquote> </div>urn:uuid:0170b329-1cff-36c1-ad41-c88c5fba0ea7deanwampler2009-06-03T07:31:28-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_however_java_was_a_child_of_i">However, Java was a child of its time. Now it shows its age. In 1995, Java provided a syntax similar enough to C++ to entice C++ developers, while avoiding many of that language&#8217;s deficiencies and &#8220;sharp edges&#8221;. Java adopted the most useful ideas for the development problems of its era, such as object-oriented programming (OOP), while discarding more troublesome techniques, such as manual memory management. These design choices struck an excellent balance that minimized complexity and maximized developer productivity, while trading-off performance compared to natively-compiled code. While Java has evolved since its birth, many people believe it has grown too complex without adequately addressing some newer development challenges.</p> <blockquote><p>Yea, our intention isn't to provide a detailed comparison between C++ and Java, but just to indicate the sea change Java represented at the time and to argue that we need another sea change now. </p> &#8212; deanwampler (2009-06-03 07:30:42) </blockquote> </div>urn:uuid:5346cd91-d933-3cf1-8f66-51e08889fa72deanwampler2009-06-03T07:30:42-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_why_scala2">To meet these challenges, many developers are looking for new languages and tools. Venerable standbys like Java, C#, and C++ are no longer optimal for developing the next generation of applications.</p> <blockquote><p>It's true that Microsoft has kept C# moving forward at a faster rate than Java. However, It is still based on design choices that I think are sub-optimal, like not using type inferencing from the very beginning. C# won't be able to move to more comprehensive type inferencing than it supports now because of the potential parsing ambiguities its syntax would cause.<br /> </p> &#8212; deanwampler (2009-06-03 07:28:41) </blockquote> </div>urn:uuid:abd49473-3a39-3fbe-9b23-5eaafeaad5a5deanwampler2009-06-03T07:28:41-07:00Comment on 'Why Scala?' <div>A Taste of Concurrency <p id="para_five_messages_are_sent_to_the_">Five messages are sent to the actor, using the syntax <code class="literal">actor ! message</code>. The first message sends a <code class="literal">Circle</code> instance. The actor &#8220;draws&#8221; the circle. The second message sends a <code class="literal">Rectangle</code> message. The actor &#8220;draws&#8221; the rectangle. The third message does the same thing for a <code class="literal">Triangle</code>. The fourth message sends a <code class="literal">Double</code> that is approximately equal to <span class="emphasis"><em>Pi</em></span>. This is an unknown message for the actor, so it just prints an error message. The final message sends an &#8220;exit&#8221; string, which causes the actor to terminate.</p> <blockquote><p>Typo: it says "The four message sends...", it should say "The fourth message sends...". </p> &#8212; chifazo (2009-05-30 12:24:30) </blockquote> </div>urn:uuid:abe3bc29-eca2-3b16-bd9a-aadc7eb244cachifazo2009-05-30T12:24:30-07:00Comment on 'A Taste of Concurrency' <div>Why Scala? <p id="para_however_java_was_a_child_of_i">However, Java was a child of its time. Now it shows its age. In 1995, Java provided a syntax similar enough to C++ to entice C++ developers, while avoiding many of that language&#8217;s deficiencies and &#8220;sharp edges&#8221;. Java adopted the most useful ideas for the development problems of its era, such as object-oriented programming (OOP), while discarding more troublesome techniques, such as manual memory management. These design choices struck an excellent balance that minimized complexity and maximized developer productivity, while trading-off performance compared to natively-compiled code. While Java has evolved since its birth, many people believe it has grown too complex without adequately addressing some newer development challenges.</p> <blockquote><p>oops. Page 8: http://books.google.com/books?id=VGT1_UJzjM0C&amp;pg=PA1371&amp;dq=.NET+Apress#PPA8,M1 </p> &#8212; ederandres_an (2009-05-29 07:33:31) </blockquote> </div>urn:uuid:8c2dcd90-06a4-3c63-a9cf-c825ee2dd657ederandres_an2009-05-29T07:33:31-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_however_java_was_a_child_of_i">However, Java was a child of its time. Now it shows its age. In 1995, Java provided a syntax similar enough to C++ to entice C++ developers, while avoiding many of that language&#8217;s deficiencies and &#8220;sharp edges&#8221;. Java adopted the most useful ideas for the development problems of its era, such as object-oriented programming (OOP), while discarding more troublesome techniques, such as manual memory management. These design choices struck an excellent balance that minimized complexity and maximized developer productivity, while trading-off performance compared to natively-compiled code. While Java has evolved since its birth, many people believe it has grown too complex without adequately addressing some newer development challenges.</p> <blockquote><p>Java solved many plumbing problems related with C++ programming such as static and dynamic memory management. Also, Java developers had a more legible, well looked sintaxis. So we can say that Java is a cleaner version of C++. </p> <p>-- this is based on Andrew Troelsen's book: http://books.google.com/books?id=VGT1_UJzjM0C&amp;pg=PA1371&amp;dq=.NET+Apress#PPA7,M1 </p> &#8212; ederandres_an (2009-05-29 07:30:15) </blockquote> </div>urn:uuid:aab56e5a-937c-3c0d-806a-d074bdbf273federandres_an2009-05-29T07:30:15-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_the_name__scala__is_a_contract">The name <span class="emphasis"><em>Scala</em></span> is a contraction of the words <span class="emphasis"><em>scalable language</em></span>. While this suggests that the pronunciation should be <span class="emphasis"><em>scale-ah</em></span>, the creators of Scala actually pronounce it <span class="emphasis"><em>scah-lah</em></span>, like the Italian word for &#8220;stairs&#8221;. That is, the two &#8220;a&#8217;s&#8221; are pronounced the same.</p> <blockquote><p>Don't quite know where to put this comment, but would be nice to see mention of where a scalable language fits within a cloud filled internet. I like things to scale (duhhh) and it may be worthwhile to include how scala could fit within an ASP cloud model of deployment. </p> &#8212; prawsthorne (2009-05-26 09:00:30) </blockquote> </div>urn:uuid:2f1007a8-2fe2-33b1-815c-5e0a7292112dprawsthorne2009-05-26T09:00:30-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_why_scala2">To meet these challenges, many developers are looking for new languages and tools. Venerable standbys like Java, C#, and C++ are no longer optimal for developing the next generation of applications.</p> <blockquote><p>C# venerable? Please qualify... Given the evolution of C# language from 1.0 - next major version 4.0, not to mention enhancements to the class library and the CLR, it is not clear to me how C# can be viewed as venerable... </p> &#8212; jungho (2009-05-23 22:09:28) </blockquote> </div>urn:uuid:0edf5804-7e26-35e3-a1ce-cf02832e16efjungho2009-05-23T22:09:28-07:00Comment on 'Why Scala?' <div>A Taste of Concurrency <p id="para_there_are_many_reasons_to_be_s">There are many reasons to be seduced by Scala. One reason is the <code class="literal">Actors</code> API included in the Scala library, which is based on the robust <code class="literal">Actors</code> concurrency model built into Erlang <a class="xref" href="apa.html#Haller2007">[Haller2007]</a>. Here is an example to whet your appetite.</p> <blockquote><p>"built-in Actors library" reads a bit like as if Actors were part of the Scala Language definition; a stronger hint, that Actors in Scala are "just" a library would IMHO be good. Together with Steven's comment above, maybe: "One reason is Scala's Actors library, a concurrency API based on the Erlang's Actors concurrency model." ... removed "robust" due to the "New Lift Actor code" Mail by David Pollak in the Lift Google Group ... which might make a nice side note showing off Scala's flexibility :-) </p> &#8212; battisti (2009-05-23 16:48:03) </blockquote> </div>urn:uuid:a4a78310-131b-3c6d-b84d-03b5706e3aa2battisti2009-05-23T16:48:03-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_on_the_last_line_using_an_ob">On the last line, using an <code class="literal">object</code> rather than a <code class="literal">class</code> simplifies the code. Instead of creating an instance with <code class="literal">new Upper</code>, we can just call the <code class="literal">upper</code> method on the <code class="literal">Upper</code> object directly (note how this looks like the syntax you would use when calling static methods in a Java class).</p> <blockquote><p>Adding a little note explaining that this is also the actual syntax when accessing static methods in Java libraries from Scala code would informative for Java converts or people interested in Scala because of the large number of available (Java) libraries. </p> &#8212; battisti (2009-05-23 16:30:45) </blockquote> </div>urn:uuid:bd69abaa-38e6-3b42-970f-f1f63a70aefabattisti2009-05-23T16:30:45-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_on_the_first_line_upper_is_">On the first line, <code class="literal">Upper</code> is now declared as an <code class="literal">object</code>, which is a <span class="emphasis"><em>singleton</em></span>. We are declaring a class, but the Scala runtime will only ever create one instance of <code class="literal">Upper</code>. (You can&#8217;t write <code class="literal">new Upper</code>, for example.) Scala uses <code class="literal">objects</code> for situations where other languages would use &#8220;class-level&#8221; members, like <code class="literal">statics</code> in Java. We don&#8217;t really need more than one <span class="emphasis"><em>instance</em></span> here, so a singleton is fine.</p> <blockquote><p>This is probably just some nitpicking, but is "declared as an object, which is a singleton class" correct? According to the Scala Reference it: "defines a single object of a new class", while a "singleton class" is a class used to implement the singleton pattern... these two concepts are of course related, but in Scala object definitions are also used as a mechanism for creating modules (which AFAIK is usually not the case when using a Singleton Pattern, which got a bad reputation in the last years). </p> &#8212; battisti (2009-05-23 16:23:40) </blockquote> </div>urn:uuid:89d3fa17-0f8d-36d6-8bd4-a53ca2583a38battisti2009-05-23T16:23:40-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_takes_a_single_string_argume">It takes an argument list with a single <code class="literal">String</code> argument named <code class="literal">s</code>. The body of the function literal is after the &#8220;arrow&#8221;, <code class="literal">=&gt;</code>. It calls <code class="literal">toUpperCase()</code> on <code class="literal">s</code>. The result of this call is returned by the function literal. In Scala, the last <span class="emphasis"><em>expression</em></span> in a function is the return value, although you can have <code class="literal">return</code> statements elsewhere, too. The <code class="literal">return</code> keyword is optional here and it is rarely used, except when returning out of the middle of a block (<span class="emphasis"><em>e.g.,</em></span> in an <code class="literal">if</code> statement).</p> <blockquote><p>Using the following "Note" to explaining why "return" is rarely used in scala (interfering with type inference, with an appropriate reference to the section explaining type inference) might be informative for readers only accustomed to Java </p> &#8212; battisti (2009-05-23 16:03:41) </blockquote> </div>urn:uuid:23f0dbc8-0420-354f-9a27-318313d5746abattisti2009-05-23T16:03:41-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_the_method_body_calls_the_map">The method body calls the <code class="literal">map</code> method on the <code class="literal">strings</code> array, which takes a <span class="emphasis"><em>function literal</em></span> as an argument. Function literals are &#8220;anonymous&#8221; functions. They are similar to <span class="emphasis"><em>lambdas</em></span>, <span class="emphasis"><em>closures</em></span>, <span class="emphasis"><em>blocks</em></span>, or <span class="emphasis"><em>procs</em></span> in other languages. In Java, you would have to use an anonymous inner class here that implements a method defined by an interface, <span class="emphasis"><em>etc.</em></span></p> <blockquote><p>If you're hinting at the similarity with lambdas/blocks in Ruby, adding "closures" at this point might be helpful for readers not familiar with Ruby. </p> &#8212; battisti (2009-05-23 15:57:44) </blockquote> </div>urn:uuid:c23a01ef-fbc8-3ee0-b24f-08baa97d5cdebattisti2009-05-23T15:57:44-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_let_s_examine_the_code_in_deta">Let&#8217;s examine the code in detail, so we can begin to learn Scala syntax. There are a lot of details in just six lines of code! We&#8217;ll explain the general ideas here. All the ideas used in this example will be explained more thoroughly in later sections of the book.</p> <blockquote><p>Is this paragraph really helpful? Of course you're going to explain the ideas contained in this first program more thoroughly later :-) </p> &#8212; battisti (2009-05-23 15:49:15) </blockquote> </div>urn:uuid:c04df5a4-ce5c-35b7-a760-84fbbd1f8054battisti2009-05-23T15:49:15-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_to_run_this_script_go_to_a_co">To run this script, go to a command window, change to the same directory and run the following command.</p> <blockquote><p>Of course you point this out half a page down. Ah well. :-) </p> &#8212; delitescere (2009-05-23 08:16:04) </blockquote> </div>urn:uuid:1207a05b-fb18-3c4b-84c9-12012a19baaddelitescere2009-05-23T08:16:04-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_to_run_this_script_go_to_a_co">To run this script, go to a command window, change to the same directory and run the following command.</p> <blockquote><p>As it's one of Scala's selling points, might as well keep things as concise as possible (or at least make a note of not being so to aid with initial learning). </p> <ul> <li> <code>(s:String)</code> the type specification is redundant </li> <li> <code>Console.</code> is also redundant </li> </ul> &#8212; delitescere (2009-05-23 08:12:15) </blockquote> </div>urn:uuid:7b8c4c8c-1279-31d7-88ca-0c2d91bb5815delitescere2009-05-23T08:12:15-07:00Comment on 'A Taste of Scala' <div>A Taste of Concurrency <p id="para_recall_that_we_declared_draw_">Recall that we declared <code class="literal">draw</code> as an abstract method in <code class="literal">Shape</code> and we implemented <code class="literal">draw</code> in the concrete subclasses. Hence, the code in the first <code class="literal">case</code> statement invokes a polymorphic operation.</p> <blockquote><p>Hopefully we also implemented draw in Triangle! </p> &#8212; generex (2009-05-21 09:41:51) </blockquote> </div>urn:uuid:6a0fd509-b6c8-3337-b452-c937273fb064generex2009-05-21T09:41:51-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_the_last_line_is_the_prompt_th">The last line is the prompt that is waiting for your input. The interactive mode of the <strong class="userinput"><code>scala</code></strong> command is very convenient for experimentation (see <a class="xref" href="ch14.html#CommandLineToolScala" title="The scala Command Line Tool">the section called &#8220;The scala Command Line Tool&#8221;</a> in <a class="xref" href="ch14.html" title="Chapter&#160;14.&#160;Scala Tools, Libraries and IDE Support">Chapter&#160;14, <i>Scala Tools, Libraries and IDE Support</i></a> for more details). An interactive interpreter like this is called a REPL: <span class="emphasis"><em>Read, Evaluate, Print, Loop</em></span>.</p> <blockquote><p>Test </p> &#8212; bz7 (2009-05-21 08:20:04) </blockquote> </div>urn:uuid:b94dac3c-73da-3d3c-9041-21546ddf385cbz72009-05-21T08:20:04-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_you_can_also_use_this_short_ha">You can also use this short-hand syntax in some more complex function literals, as we will see in <a class="xref" href="ch03.html" title="Chapter&#160;3.&#160;Rounding Out the Essentials">Chapter&#160;3, <i>Rounding Out the Essentials</i></a>.</p> <blockquote><p>@Marek: This was just a bug in the rendering system that was dropping the cross reference text. It's been fixed. </p> &#8212; abdelazer (2009-05-20 19:02:47) </blockquote> </div>urn:uuid:3f0e0358-220f-3b50-b050-2f417c691092abdelazer2009-05-20T19:02:47-07:00Comment on 'A Taste of Scala' <div>A Taste of Concurrency <p id="para_the_point_class_represents_a">The <code class="literal">Point</code> class represents a two-dimensional point on a plane. Note the argument list after the class name. Those are constructor parameters. In Scala, the <span class="emphasis"><em>whole</em></span> class body is the constructor, so you list the arguments for the <span class="emphasis"><em>primary</em></span> constructor after the class name and before the class body. (We&#8217;ll see how to define auxiliary constructors in <a class="xref" href="ch05.html#Constructors" title="Constructors in Scala">the section called &#8220;Constructors in Scala&#8221;</a> in <a class="xref" href="ch05.html" title="Chapter&#160;5.&#160;Basic Object-Oriented Programming in Scala">Chapter&#160;5, <i>Basic Object-Oriented Programming in Scala</i></a>.) Because we put the <code class="literal">val</code> keyword before each parameter declaration, they are automatically converted to read-only fields with the same names with public reader methods of the same name. That is, when you instantiate a <code class="literal">Point</code> instance, <span class="emphasis"><em>e.g.</em></span>, <code class="literal">point</code>, you can read the fields using <code class="literal">point.x</code> and <code class="literal">point.y</code>. If you want <span class="emphasis"><em>mutable</em></span> fields, then use the keyword <code class="literal">var</code>. We&#8217;ll explore variable declarations and the <code class="literal">val</code> and <code class="literal">var</code> keywords in <a class="xref" href="ch02.html#VariableDeclarationsAndDefinitions" title="Variable Declarations">the section called &#8220;Variable Declarations&#8221;</a> in <a class="xref" href="ch02.html" title="Chapter&#160;2.&#160;Type Less, Do More">Chapter&#160;2, <i>Type Less, Do More</i></a>.</p> <blockquote><p>Typo: "auxiliary constructors in in " </p> &#8212; steven807 (2009-05-20 17:08:05) </blockquote> </div>urn:uuid:ff278df9-2689-3c95-8252-d362d332add5steven8072009-05-20T17:08:05-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Concurrency <p id="para_there_are_many_reasons_to_be_s">There are many reasons to be seduced by Scala. One reason is the <code class="literal">Actors</code> API included in the Scala library, which is based on the robust <code class="literal">Actors</code> concurrency model built into Erlang <a class="xref" href="apa.html#Haller2007">[Haller2007]</a>. Here is an example to whet your appetite.</p> <blockquote><p>In Erlang, there is no "Actors" library -- the concurrency in Erlang is part of the language. </p> &#8212; steven807 (2009-05-20 17:06:45) </blockquote> </div>urn:uuid:331fb6b9-2564-304c-892f-b9495ab53046steven8072009-05-20T17:06:45-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_in_this_example_the_upper_m">In this example, the <code class="literal">upper</code> method in the <code class="literal">Upper</code> class (no pun intended) converts the input strings to upper case and returns them in an array. The last line in the example converts four strings and prints the resulting Array.</p> <blockquote><p>Typo in blue box above: </p> <p>"We discuss these subtleties in in ." </p> &#8212; joebowbeer (2009-05-20 14:04:02) </blockquote> </div>urn:uuid:36301cf0-74ab-316a-8191-10fc1cdc8216joebowbeer2009-05-20T14:04:02-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_it_might_appear_that_oop_and_f">It might appear that OOP and FP are incompatible. In fact, a design philosophy of Scala is that OOP and FP are more synergistic than opposed. The features of one approach can enhance the other.</p> <blockquote><p>Can you really trust Scala's speed, for example: http://villane.wordpress.com/2008/02/13/scala-for-avs-while-update/ </p> <p>I think there is some other issues like reflection based implementation on structural types, boxed primitives are not well optimized (afaik). </p> <p>It's unfortunate thing, but you just can't blindly depend that compiler optimizes things to Java-speed; you have to code Java-like. </p> &#8212; clojure (2009-05-20 12:31:53) </blockquote> </div>urn:uuid:2d1baf71-baf1-3325-9361-af65de118427clojure2009-05-20T12:31:53-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_scala_is_a_language_for__profe">Scala is a language for <span class="emphasis"><em>professional</em></span> developers. Compared to languages like Java and Ruby, Scala is a more difficult language to master, because it requires competency with OOP, FP, and static typing to use it most effectively. It is tempting to prefer the relative simplicity of dynamically-typed languages. Yet, this simplicity can be deceptive. In a dynamically typed language, it is often necessary to use metaprogramming features to implement advanced designs. While metaprogramming is powerful, using it well takes experience and the resulting code tends to be hard to understand, maintain, and debug. In Scala, many of the same design goals can be achieved in a type-safe manner by exploiting its type system and mixin composition through <span class="emphasis"><em>traits</em></span>.</p> <blockquote><p>Don't you have kind of a contradiction there: "Scala is more difficult to master" and "While metaprogramming is powerful, using it well takes experience, etc" </p> <p>What does mastering really mean anyway. To get the same thing done in Scala or Ruby can be as hard if done properly (with good maintainability etc), or do you disagree? </p> &#8212; clojure (2009-05-20 12:24:38) </blockquote> </div>urn:uuid:ec8df050-eeb9-3b55-b6a5-b6aa0b9a0e06clojure2009-05-20T12:24:38-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_scala_is_compelling_because_it">Scala is compelling because it feels like a dynamically typed scripting language, due to its succinct syntax and type inference. Yet, Scala gives you all the benefits of static typing, a modern object model, functional programming, and an advanced type system. These tools let you build scalable, modular applications that can reuse legacy Java and .NET APIs and leverage the performance of the JVM and CLR.</p> <blockquote><p>Scala's syntax is not particularly succinct, even for statically typed language, compare it to Haskell, or ML based languages. </p> &#8212; clojure (2009-05-20 12:21:11) </blockquote> </div>urn:uuid:5bb81f81-9fcc-3f98-9433-c1824cb3a68eclojure2009-05-20T12:21:11-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_we_have_worked_with_both_stati">We have worked with both static and dynamic languages, at various times. We find both kinds of languages compelling for different reasons. We believe the modern software developer must master a range of languages and tools. Sometimes, a dynamic language will be the right tool for the job. At other times, a static language like Scala is just what you need.</p> <blockquote><p>This paragraph could be made much concise without losing meaning. </p> &#8212; clojure (2009-05-20 12:19:27) </blockquote> </div>urn:uuid:dbfed3bb-79e6-362b-8ae6-be34764f50efclojure2009-05-20T12:19:27-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_it_might_appear_that_oop_and_f">It might appear that OOP and FP are incompatible. In fact, a design philosophy of Scala is that OOP and FP are more synergistic than opposed. The features of one approach can enhance the other.</p> <blockquote><p>"Of the set of newer JVM languages, Scala is the only one that is statically typed." </p> <p>With the exceptions of CAL and JavaFX. </p> &#8212; ricky_clarkson (2009-05-20 12:18:45) </blockquote> </div>urn:uuid:60f4e353-6b12-3400-bb3b-3d21c386919ericky_clarkson2009-05-20T12:18:45-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_the_never_ending_need_to_scale">The never-ending need to scale is driving architectures towards pervasive concurrency. However, Java&#8217;s concurrency model, which is based on synchronized access to shared, mutable state, results in complex and error-prone programs.</p> <blockquote><p>Scala is OO based which is almost inherently embraces mutability. This is a long way from Clojure's approach. Actors model is sufficient only for a limited segment of problems. </p> &#8212; clojure (2009-05-20 12:15:42) </blockquote> </div>urn:uuid:c4461557-30ec-3e09-8387-84f1f48fde50clojure2009-05-20T12:15:42-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_despite_their_productivity_adv">Despite their productivity advantages, <span class="emphasis"><em>dynamic</em></span> languages may not be the best choices for all applications, particularly for very large code bases and high-performance applications. There is a longstanding, spirited debate in the programming community about the relative merits of dynamic <span class="emphasis"><em>vs.</em></span> static typing. Many of the points of comparison are somewhat subjective. We won&#8217;t go through all the arguments here, but we will offer a few thoughts for consideration.</p> <blockquote><p>I'd say that static typing isn't only about what types variables have, but also what types expressions have. </p> &#8212; ricky_clarkson (2009-05-20 12:15:02) </blockquote> </div>urn:uuid:9eb8edac-0276-3cb6-b60d-de20855497ecricky_clarkson2009-05-20T12:15:02-07:00Comment on 'Why Scala?' <div>A Taste of Concurrency <p id="para_all_the_methods_and_public_fie">All the methods and public fields from <code class="literal">Actor</code> are imported. These are not <code class="literal">static</code> imports from the <code class="literal">Actor</code> type, as they would be in Java. Rather, they are imported from an <code class="literal">object</code> that is also named <code class="literal">Actor</code>. The <code class="literal">class</code> and <code class="literal">object</code> can have the same name, as we will see in <a class="xref" href="ch06.html#CompanionObjects" title="Companion Objects">the section called &#8220;Companion Objects&#8221;</a> in <a class="xref" href="ch06.html" title="Chapter&#160;6.&#160;Advanced Object-Oriented Programming In Scala">Chapter&#160;6, <i>Advanced Object-Oriented Programming In Scala</i></a>.</p> <blockquote><p>Typo last sentence: as we will see in ... </p> &#8212; jasonh (2009-05-20 07:14:53) </blockquote> </div>urn:uuid:53ff19f7-010c-3f95-898f-293ad4088f35jasonh2009-05-20T07:14:53-07:00Comment on 'A Taste of Concurrency' <div>A Taste of Scala <p id="para_the_cp_option_adds_he_cur">The <strong class="userinput"><code>-cp .</code></strong> option adds the current directory to the search &#8220;class path&#8221;. You should get the following output.</p> <blockquote><p>Typo above. Should read ... adds <em>the</em> current directory... </p> &#8212; jasonh (2009-05-20 06:49:03) </blockquote> </div>urn:uuid:1ddd26ae-ca77-3f0e-a0a5-79665c422afajasonh2009-05-20T06:49:03-07:00Comment on 'A Taste of Scala' <div>A Taste of Scala <p id="para_you_can_also_use_this_short_ha">You can also use this short-hand syntax in some more complex function literals, as we will see in <a class="xref" href="ch03.html" title="Chapter&#160;3.&#160;Rounding Out the Essentials">Chapter&#160;3, <i>Rounding Out the Essentials</i></a>.</p> <blockquote><p>The chapter reference is missing here (mentioning it in case you have missed it). </p> &#8212; Leonidas (2009-05-20 01:08:38) </blockquote> </div>urn:uuid:3393f716-6a7c-3212-9747-099d6a9a0ca0Leonidas2009-05-20T01:08:38-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_it_might_appear_that_oop_and_f">It might appear that OOP and FP are incompatible. In fact, a design philosophy of Scala is that OOP and FP are more synergistic than opposed. The features of one approach can enhance the other.</p> <blockquote><p>You could elaborate about the OOP bits a litte bit more, since it is most likely the thing that Scala beginners coming from most other languages are most familiar with. You could for example say that there are no primitive types which makes the OOP types integrate better into the code freeing the programmer from bothering with this (or just say "everything is an object" which is more relevant to OOP than FP). </p> &#8212; Leonidas (2009-05-20 01:00:51) </blockquote> </div>urn:uuid:c4e65acf-7195-35bc-98d8-c0b5f0aa8d34Leonidas2009-05-20T01:00:51-07:00Comment on 'Why Scala?' <div>Why Scala? <p id="para_developers_want_languages_that">Developers want languages that are more succinct and flexible to improve their productivity. This is one reason why so-called &#8220;scripting&#8221; languages like Ruby and Python have become more popular recently.</p> <blockquote><p>I'd say that not only Ruby has become more popular, but also Python and Clojure, another new popular language for the JVM. </p> &#8212; Leonidas (2009-05-20 00:54:36) </blockquote> </div>urn:uuid:beebd5bf-efb8-3a69-9ab3-a8ae797c21b0Leonidas2009-05-20T00:54:36-07:00Comment on 'Why Scala?' <div>A Taste of Scala <p id="para_note_that_this_code_is_fully_t">Note that this code is fully thread safe. We don&#8217;t declare any variables that might cause thread-safety issues. The API methods we use are also thread-safe. Therefore, we don&#8217;t need multiple instances. A singleton <code class="literal">object</code> works fine.</p> <blockquote><p>It's not clear at all how the example code could possibly <em>not</em> be thread-safe in Scala or any other language since state has not even been introduced yet. </p> <p>I think the point you are trying to make is that it is a little bit tricky to implement the Singleton pattern in Java without introducing subtle concurrency problems, while in Scala you can just use an 'object' as a singleton without such concerns.<br /> </p> &#8212; brl (2009-05-19 19:45:44) </blockquote> </div>urn:uuid:6e85100a-7c31-3faa-b45a-80919b605f60brl2009-05-19T19:45:44-07:00Comment on 'A Taste of Scala' <div>Why Scala? <p id="para_however_java_was_a_child_of_i">However, Java was a child of its time. Now it shows its age. In 1995, Java provided a syntax similar enough to C++ to entice C++ developers, while avoiding many of that language&#8217;s deficiencies and &#8220;sharp edges&#8221;. Java adopted the most useful ideas for the development problems of its era, such as object-oriented programming (OOP), while discarding more troublesome techniques, such as manual memory management. These design choices struck an excellent balance that minimized complexity and maximized developer productivity, while trading-off performance compared to natively-compiled code. While Java has evolved since its birth, many people believe it has grown too complex without adequately addressing some newer development challenges.</p> <blockquote><p>It seems a little bit strange to describe garbage collection as 'discarding more troublesome techniques such as manual memory management'. Maybe you could name garbage collection directly as one of the useful ideas that Java adopted. </p> &#8212; brl (2009-05-19 18:38:12) </blockquote> </div>urn:uuid:e1da5a52-ffc4-31c7-b935-c5e728ea99b1brl2009-05-19T18:38:12-07:00Comment on 'Why Scala?'