JOB REFERRALS
    ON THIS PAGE
    ARCHIVES
    CATEGORIES
    BLOGROLL
    LINKS
    SEARCH
    MY BOOKS
    DISCLAIMER
 
 Thursday, March 02, 2006
Scala reactions

Apparently, I touched a nerve with that last post; predictably, people started counting the keystrokes and missing my point. For example, Mark Blomsma wrote:

Looks to me like you're comparing apples and pears.

C# does not force you to use accessors. The following is already a lot closer to Scala.

public class Person
{
public string firstName; public string lastName; public Person spouse;

public Person(string fn, string ln, Person s)
{
firstName = fn; lastName = ln; spouse = s;
}

public Person(string fn, string ln) : this(gn, ln, null) { }

public string Introduction()
{
return "Hi, my name is " + firstName + " " + lastName +
(spouse != null ?
" and this is my spouse, " + spouse.firstName + " " + spouse.lastName + "." :
".");
}
}

This is only 356 keystrokes, compared to 287 for Scala. Now in Scala the default accessor for classes and members seems to be public, if this were not the case then you'd need 323 keystrokes in Scala.
Only a very minor difference. And definately not enough to make a case that Scala is more efficient for a developer.

Another consideration if you start talking keystrokes is that the tooling suddenly becomes a factor. With C# and VS2005 I only type 'prop,tab,tab' and then the type and name info. Skipping quite some keystrokes.
Mark, with all due respect, I gotta admit to believing that you're doing the apples-to-pears comparison here, at least with your definition of the Person class in C#. The Scala implementation does NOT define a public field, but accessor methods, thus preserving encapsulation in the same way that the property methods do in C# and Java and C++. The thing is, Scala just realizes that 80% of those methods are always coded the same way, so it assumes a default implementation when it sees that syntax. (Ruby does the same thing.)

All that sort of misses the point, though: the purpose of the comparison was not to count keystrokes, per se, but to look at the expressiveness of the language and how concisely the language can express a concept without requiring a great deal of scaffolding. C, for example, could always be used to build object-oriented systems... but you had a lot of work to do on your own to do it. As a result, a huge amount of complexity was spent in manaing the relationships between "classes" by hand (by tracking pointer relationships and so on). C++ solved a lot of that by baking those concepts in as a first-class concept, thus reducing the surface area requirment in the programmer's mind devoted to "plumbing", and making room for more business-level complexity. Java did the same to C++ by introducing GC and other VM-level support, and so on. Scala and Ruby (and other hybrid and/or dynamic languages) are now seeking to do the same to Java and .NET.

The question of tooling is an interesting one, though: is a language just the language by itself, or the language plus the tools that support it? Is Lisp still Lisp if you take Emacs out of the equation? Or is Smalltalk interesting without the Smalltalk environment and/or browser? Can we separate the two? Should we? That's a question to which I don't have an easy answer.


Java/J2EE | .NET | C++ | Ruby | XML Services

Thursday, March 02, 2006 10:41:16 PM (Pacific Standard Time, UTC-08:00)
Comments [9]  |  Related posts:
An Announcement
The Never-Ending Debate of Specialist v. Generalist
From the "Team-Building Exercise" Department
From the "Gosh, You Wanted Me to Quote You?" Department...
From the "You Must Be Trolling for Hits" Department...
Blog change? Ads? What gives?
Tracked by:
http://www.develop-one.net/blog/PermaLink,guid,c23468b8-d7db-4ec0-8c15-71f2b5a15... [Pingback]
"general rv michigan" (on line) [Trackback]
"http://9nu-information.info/80752523/index.html" (http://9nu-information.info/8... [Pingback]
"http://9ne-information.info/62663343/index.html" (http://9ne-information.info/6... [Pingback]
"http://9nk-information.info/28103486/index.html" (http://9nk-information.info/2... [Pingback]
"http://9nu-information.info/71685869/index.html" (http://9nu-information.info/7... [Pingback]
"http://9nf-information.info/56361779/index.html" (http://9nf-information.info/5... [Pingback]
"http://9ni-information.info/35586857/index.html" (http://9ni-information.info/3... [Pingback]
"http://9nv-information.info/15460795/index.html" (http://9nv-information.info/1... [Pingback]
Friday, March 03, 2006 1:32:41 AM (Pacific Standard Time, UTC-08:00)
The difference I see between Java/C# and Ruby (I don't know Scala) in the example that was given is the classic difference between OO compiled and scripting languages. Everyone knows you need less lines of code to do something in a scripting language, that's one of the advantages. Furthermore, I'm not a fan of language tools for code-generation simply because I never agree with the code that is generated and often it's a terrible pain to go patch the generated code with business methods and small specifics, but I think that an industrialized development process cannot be done without the tools that come with the language. It's just a problem of productivity and scale of development.
For me a concise OO language could look something like this : "I'm X. a, b and c are my attributes.Y and Z are my sons. I can do this and this... X, do this with these...etc.". It's more like a parody, but I cannot go more concise than this, supressing primitive types, supressing the 100 constructors, etc.
Friday, March 03, 2006 5:26:46 AM (Pacific Standard Time, UTC-08:00)
> Is Lisp still Lisp if you take Emacs out of the
> equation? Or is Smalltalk interesting without the
> Smalltalk environment and/or browser? Can we
> separate the two? Should we? That's a question to
> which I don't have an easy answer.

To my mind, you indeed *must* be able to separate this.

The language is built by expressions, statements, syntax and semantics. A "text", expressing a problem solution, shall be principally writable in whatever tool I have, even wrapped inside a prosa text in a Word processor, or maybe in NotePad or even as echo-statements in a shell (I remember a very,very bad remote support session many years ago ;-) ).
The written "text" should be readable and as best as possible understandable, even in a printout.

So if you *need* a very specialised tool to write the code or (even worse) to read it, this should be considered a K.O. criterion.

(Regarding Emacs: One can write Scheme code in a MemoPad on a PDA ... such things should always be possible).

Comparing languages should really be done by writing them in NotePad (no highlights, no macros) and reading them in unformatted text mode.
Productivity is: How long does it take a programmer to solve a given task in language X *with NotePad*?
How long does it take for *another* person to understand that program printed on paper?

"Tools" shall be what they are: Helpers or utilities to *ease* life, not a oxygene aggregate necessary to make survival possible.

Only that way I can OTOH achieve what the pragmatic programmers advice: "Use a Single Editor Well".
(see: http://www.pragmaticprogrammer.com/ppbook/extracts/rule_list.html)
Even if I use different languages in different situations.
Friday, March 03, 2006 11:14:30 AM (Pacific Standard Time, UTC-08:00)
I think that all of this misses the point entirely. The tools and languages of choice play a very small part in how efficient one is as a programmer.

I inherited some C# code recently that implemented its own ASCII to UNICODE function.

strBytes = new byte[(len + 1) * 2];
int n;

for (n=0; n < len; n++)
{
strBytes[n * 2] = (byte)str[n];
strBytes[n * 2 + 1] = 0;
}
strBytes[n * 2] = 0;
strBytes[n * 2 + 1] = 0;

Of course, that's a few more strokes than:

Byte[] unicodeBytes = Encoding.Unicode.GetBytes(str);

No matter how terse the language or how magical the toolset, there is no compensating for just plain old knowing what the heck you are doing.

Friday, March 03, 2006 12:58:35 PM (Pacific Standard Time, UTC-08:00)
That is a perfectly fair comparison. Using Eclipse to write Java, you'd hit New, Java Class, Person, then insert the parameters in your constructor:

public class Person {
public Person(String firstName, String lastName, Person spouse) {
this.firstName = firstName;
this.lastName = lastName;
this.spouse = spouse;
}

Each of those this. lines will be red-underlined as an error. Hit Ctrl-1 to Quick Fix, Create Field, and you have an appropriate field.

Hit Source, Generate Getters & Setters, Select All, OK, and you have all your accessors.

I just did this, with no cut-and-paste. It took me 35 seconds.

Dynamic languages don't make a lick of difference in this area, and I have written very large Python applications. There are advantages to Python and other scripting languages for small programs and rapid prototyping, but saving a few bytes of source now in exchange for the maintenance nightmare of a large dynamic program is not a wise trade-off.


Friday, March 03, 2006 5:53:23 PM (Pacific Standard Time, UTC-08:00)
Mark, and then you have 4 times the amount of code to read and maintain (than, say, Ruby).

Part of why I like Ruby is that you don't need an editor. vim is all I need.
Joe
Saturday, March 04, 2006 6:04:41 AM (Pacific Standard Time, UTC-08:00)
Ok. It seems my limited knowledge of Scala makes that I did not realize that 'def X' is actually an accessor method. I've tried to look up what the syntax would be if you wish to add behaviour in Scala and I found the following on
http://scala.epfl.ch/examples/files/timeofday.html :

===

object timeofday {

class DateError extends java.lang.Exception;

/**
* Simulating properties in Scala
* (example 4.2.1 in ScalaReference.pdf)
*/
class TimeOfDayVar {
private var h: int = 0;
private var m: int = 0;
private var s: int = 0;
def hours = h;
def hours_= (h: int) =
if (0 <= h && h < 24) this.h = h
else throw new DateError();
def minutes = m;
def minutes_= (m: int) =
if (0 <= m && m < 60) this.m = m
else throw new DateError();
def seconds = s;
def seconds_= (s: int) =
if (0 <= s && s < 60) this.s = s
else throw new DateError();
}

def main(args: Array[String]): Unit = {
val d = new TimeOfDayVar;
d.hours = 8; d.minutes = 30; d.seconds = 0;
d.hours = 25; // throws a DateError exception
}

}

===

So it appears to me that in order for a property to seperate data from behaviour it is still good practice to define a private variable.

Just a quick response to Joe: Even though the example shows only to get/set a value we need to remember that the reason for having accessor methods in the first place is because we expects to add behaviour. If we are sure we'll never do that OR we know that we're allowed to change/break the objects interface then we can start out by just using public fields and 'upgrade' to accessor methods when the time is right.

The question of 'What is a language without tooling?' seems to be a much more interesting one.
If I take the 'real' world, what would the English language be if no one had a mouth to actually produce a audio version of the language?

In code there is no interest in an audio version, only in a written, electronic, compilable version. We can write C# on a piece of paper and for intends and purposes it would be useless.

Now if I have a stutter, then I can still produce English, but I'd be a poor speaker. However to me, English still holds value because even though limited, speaking English will help me get through life and achieve any number of goals.

Back to C#. C# as a language allows me to 'speak' to my CPU. If I have poor tooling like say notepad, then I can still speak to the CPU. The productivity of me as a professional developer would however be very poor. So in terms of business this solution would hold no value.

So back to the original question: is a language just the language by itself, or the language plus the tools that support it?
My 2 cents answer:

Academically speaking a language is a language as soon as it is defined. Without tools which enable use of the language as a means to succesfully achieve (business) goals the language is however useless.

Ofcourse there are many different goals, for instance Pascal is still used in many schools to get students started with programming. So not every goals needs to be profit driven.
Wednesday, March 08, 2006 1:42:44 AM (Pacific Standard Time, UTC-08:00)
The Scala code is also not optimal. The same can be expressed as
class Person(val firstName: String, val lastName: String, val spouse: Person) {
def this(fn: String, ln: String) = this(fn, ln, null);
def introduction: String = "Hi, my name is " +
firstName + " " + lastName +
(if (spouse != null) " and this is my spouse, " +
spouse.firstName + " " + spouse.lastName + "."
else ".");
}

The key is marking the primary constructor parameters with the 'val' keyword which makes them publicly avaiable. You can use 'var' to make them variables rahter than values. You can also apply access or 'override' modifiers.
Nikolay
Tuesday, October 10, 2006 2:27:32 AM (Pacific Daylight Time, UTC-07:00)
http://lahass.com/absolutxsalopesx/ hit1 http://lahass.com/adolescentesxsalopesx/ hit2 http://lahass.com/adultexsalopesx/ hit3 http://lahass.com/aimexsalopesx/ hit4 http://lahass.com/analexsalopesx/ hit5 http://lahass.com/analesxsalopesx/ hit6 http://lahass.com/arabxsalopesx/ hit7 http://lahass.com/arabexsalopesx/ hit8 http://lahass.com/arabesxsalopesx/ hit9 http://lahass.com/arabsexxsalopesx/ hit10 http://lahass.com/asianxsalopesx/ hit11 http://lahass.com/asiatiquesxsalopesx/ hit12 http://lahass.com/baisexsalopesx/ hit13 http://lahass.com/baiserxsalopesx/ hit14 http://lahass.com/bellexsalopesx/ hit15 http://lahass.com/bellesxsalopesx/ hit16 http://lahass.com/beurettexsalopesx/ hit17 http://lahass.com/beurettesxsalopesx/ hit18 http://lahass.com/blackxsalopesx/ hit19 http://lahass.com/blondexsalopesx/ hit20 http://lahass.com/boulesxsalopesx/ hit21 http://lahass.com/charmesxsalopesx/ hit22 http://lahass.com/clipsxsalopesx/ hit23 http://lahass.com/destructionxsalopesx/ hit24 http://lahass.com/dilatationsxsalopesx/ hit25 http://lahass.com/dvdxsalopesx/ hit26 http://lahass.com/ejaculationxsalopesx/ hit27 http://lahass.com/erotismexsalopesx/ hit28 http://lahass.com/extremexsalopesx/ hit29 http://lahass.com/extremesxsalopesx/ hit30 http://lahass.com/facialxsalopesx/ hit31 http://lahass.com/fellationxsalopesx/ hit32 http://lahass.com/fillesxsalopesx/ hit33 http://lahass.com/filmxsalopesx/ hit34 http://lahass.com/firstxsalopesx/ hit35 http://lahass.com/fistxsalopesx/ hit36 http://lahass.com/fotosxsalopesx/ hit37 http://lahass.com/francaisxsalopesx/ hit38 http://lahass.com/fuckxsalopesx/ hit39 http://lahass.com/galleriesxsalopesx/ hit40 http://lahass.com/gaysxsalopesx/ hit41 http://lahass.com/godexsalopesx/ hit42 http://lahass.com/grossesxsalopesx/ hit43 http://lahass.com/hardcorexsalopesx/ hit44 http://lahass.com/histoirexsalopesx/ hit45 http://lahass.com/imagesxsalopesx/ hit46 http://lahass.com/jeunexsalopesx/ hit47 http://lahass.com/jeunesxsalopesx/ hit48 http://lahass.com/joliesxsalopesx/ hit49 http://lahass.com/lauraxsalopesx/ hit50 http://lahass.com/lesbianxsalopesx/ hit51 http://lahass.com/lolitaxsalopesx/ hit52 http://lahass.com/marocainxsalopesx/ hit53 http://lahass.com/marocainexsalopesx/ hit54 http://lahass.com/masturbationxsalopesx/ hit55 http://lahass.com/mateurxsalopesx/ hit56 http://lahass.com/meilleursxsalopesx/ hit57 http://lahass.com/metissexsalopesx/ hit58 http://lahass.com/mpgxsalopesx/ hit59 http://lahass.com/nuesxsalopesx/ hit60 http://lahass.com/partousexsalopesx/ hit61 http://lahass.com/penetrationxsalopesx/ hit62 http://lahass.com/petitesxsalopesx/ hit63 http://lahass.com/picturesxsalopesx/ hit64 http://lahass.com/pipexsalopesx/ hit65 http://lahass.com/pipesxsalopesx/ hit66 http://lahass.com/pissingxsalopesx/ hit67 http://lahass.com/plaisirxsalopesx/ hit68 http://lahass.com/poiluesxsalopesx/ hit69 http://lahass.com/pornosxsalopesx/ hit70 http://lahass.com/salopexsalopesx/ hit71 http://lahass.com/salopesxsalopesx/ hit72 http://lahass.com/sauvagexsalopesx/ hit73 http://lahass.com/seinsxsalopesx/ hit74 http://lahass.com/sexesxsalopesx/ hit75 http://lahass.com/sexyxsalopesx/ hit76 http://lahass.com/sitesxsalopesx/ hit77 http://lahass.com/sodomiesxsalopesx/ hit78 http://lahass.com/teensxsalopesx/ hit79 http://lahass.com/telechargerxsalopesx/ hit80 http://lahass.com/viergexsalopesx/ hit81
gero
Saturday, November 04, 2006 5:56:54 AM (Pacific Daylight Time, UTC-07:00)
best site
http://www.onlinecasino.org.in/
Comments are closed.