tag:blogger.com,1999:blog-11683713.post3466050888939463766..comments2024-01-12T21:16:50.520-08:00Comments on Spyced: Scala: first impressionsJonathan Ellishttp://www.blogger.com/profile/11003648392946638242noreply@blogger.comBlogger21125tag:blogger.com,1999:blog-11683713.post-66398679787614196402008-05-05T01:10:00.000-07:002008-05-05T01:10:00.000-07:00I couldn't figureout how to include dependent .sca...I couldn't figureout how to include dependent .scala script files( i.e. in the source form) ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-14085508069501476762008-03-03T03:11:00.000-08:002008-03-03T03:11:00.000-08:00groovy was originally inspired by python and is de...groovy was originally inspired by python and is definitely the closest lanaguage for you to pick up. may people wrote it off because early version were pretty poor, but a new crop of developers took it over and turned it on it's head. i honestly think it is *the* easiest language to read because it is less magical than ruby but less verbose than java. not unlike python ;-)<BR/><BR/>i'd take a look at some of the groovy samples and some of the grails videos to see it in action. i think it would be much easier to adopt than scala, many people are wondering why it doesn't become java7 seeing as it has the features that people have been asking for (closures, type inference..).<BR/><BR/>on javascript, i disagree that javascript is much like java at all, their constructs can be very different. also, rhino is interpreted on the JVM whereas groovy is compiled to byte code so it enjoys good performance in most situations (with some well documented exceptions).<BR/><BR/>i'm primarily a java guy that would like to code more python, but we still have to deploy to a JVM and I find groovy a better way forward than any other option right now.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-64162050166625725472008-01-03T14:46:00.000-08:002008-01-03T14:46:00.000-08:00Thanks for the pointer, Rafael.Thanks for the pointer, Rafael.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-19975758910066527812008-01-03T13:34:00.000-08:002008-01-03T13:34:00.000-08:00Re: "Scala needs something like Python's enumerate...Re: "Scala needs something like Python's enumerate function; if you want to loop each object in a collection but you need its index too, you have to do a manual for loop."<BR/><BR/>val ls = List("a", "b", "c", "d")<BR/>ls.zipWithIndex.foreach(println)Anonymoushttps://www.blogger.com/profile/03350776762967743057noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-44440158037316989812008-01-03T05:49:00.000-08:002008-01-03T05:49:00.000-08:00I'm a newbie at scala too. I wanted to see how py...I'm a newbie at scala too. I wanted to see how python's enumerate would look in scala with closure and implicit. I came up with this draft. Sorry for the formatting.<BR/><BR/>Below is the Enumerable class and an implicity function. These allow me to write:<BR/><BR/>scala> var a = Array("hello", "from", "enumerate")<BR/>a: Array[java.lang.String] = [Ljava.lang.String;@23245e75<BR/><BR/><BR/>scala> a.enumerate { (s:String, i:Int) => println(s, i)}<BR/>(hello,0)<BR/>(from,1)<BR/>(enumerate,2)<BR/><BR/><BR/>Here is the implementation:<BR/><BR/><BR/>class Enumerable(val array: Array[String]) {<BR/>def enumerate(op: (String, Int) => Unit) {<BR/> var i = 0<BR/> for(e <- array) {<BR/> op(e, i)<BR/> i += 1<BR/> }<BR/> }<BR/><BR/>}<BR/><BR/>implicit def enumerableWrapper(a: Array[String]) = <BR/> new Enumerable(a)<BR/>}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-53979914076585247032008-01-02T10:46:00.000-08:002008-01-02T10:46:00.000-08:00Hey jonathan, you commented on my blog about scala...Hey jonathan, you commented on my blog about scala.io.Source and I see you're using it here. There is a small problem with it, it loads the entire file in memory. The code in my file was used to process some large files which caused an out of memory exception if I used scala.io.Source. <BR/><BR/>@eric<BR/>I can't wait to try out specs, I'm a long time rubyist and a heavy user of rspec. Thanks for making specs :)jaydonnellhttps://www.blogger.com/profile/13279254863158598601noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-5587374172426459692008-01-02T01:30:00.000-08:002008-01-02T01:30:00.000-08:00I'm glad that Scala gets the popularity it deserve...I'm glad that Scala gets the popularity it deserves!<BR/><BR/>I'm really a Scala fan (being tired of Java as pretty much everyone else). Yet I haven't used it much for pure scripting stuff (only when scripting involves using existing java libraries). In that case I feel much more comfortable with Ruby.<BR/>Anyway your post is interesting and I would like to know how far we can push Scala to become a "total" scripting language.<BR/><BR/>> So even the most obstinate fan of boilerplate code has absolutely no reason to keep writing unnecessary getters and setters<BR/>You can also refer to case classes where you also have equality, hashcode and pattern matching for free.<BR/><BR/>>Scala needs something like Python's enumerate function; if you want to loop each object in a collection but you need its index too, you have to do a manual for loop.<BR/>You have the method List.zipWithIndex which can help you<BR/><BR/>>Using parenthesis for collection access ("array(0); map("foo"))") makes it unnecessarily difficult to tell if you're looking at a method call or a collection access.<BR/>This is indeed a method, the "apply" one (page 55 in the book)<BR/><BR/>What I would really like to have for 2008 is lightweight script environment with autocompletion (with a less than 2s startup time,...). I don't know how feasible this is but this would make Scala a very, very interesting scripting language over the dynamic ones.<BR/><BR/>Eric.<BR/><BR/>PS: "advertising" -> if you're interested, you can have a look to my scala project (http://code.google.com/p/specs). I'm very interested in getting as much as possible (constructive ;-)) feedback about it.Erichttps://www.blogger.com/profile/16484514586929815703noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-90940186310017778102008-01-01T21:32:00.000-08:002008-01-01T21:32:00.000-08:00Thanks, Eric. Updated one last (?) time.Thanks, Eric. Updated one last (?) time.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-11414507025107983482008-01-01T19:15:00.000-08:002008-01-01T19:15:00.000-08:00Hi Jonathan,You can try that:scala hello.scala "ar...Hi Jonathan,<BR/><BR/>You can try that:<BR/><BR/>scala hello.scala "arg1" "arg2"<BR/><BR/>with hello.scala:<BR/><BR/>println("hello")<BR/>args foreach {s:String => println(s)}<BR/><BR/>This will print:<BR/><BR/>hello<BR/>arg1<BR/>arg2<BR/><BR/>Is that what you're looking for?<BR/><BR/>Eric.Erichttps://www.blogger.com/profile/16484514586929815703noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-72256536391470804002008-01-01T11:15:00.000-08:002008-01-01T11:15:00.000-08:00I started editing the post to explain that scala w...I started editing the post to explain that scala was really a decent language for short scripts after all, but couldn't figure out a way to read command-line arguments without a main method and scalac, so I ended up making only minor changes. Am I missing the obvious still? :)Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-59448821668453991812008-01-01T10:24:00.000-08:002008-01-01T10:24:00.000-08:00Ah... I totally missed that part. Duh. Thanks f...Ah... I totally missed that part. Duh. Thanks for hitting me over the head with it. :)Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-68461203207723174692008-01-01T07:37:00.000-08:002008-01-01T07:37:00.000-08:00About scala as scripting language: Did you actuall...About scala as scripting language: Did you actually try to run a "script" on the command-line via "scala myscript.scala"? I've just tested it with a file that just contained println("Hello, world") and it works just fine. No need to provide an application object or a main method.Unknownhttps://www.blogger.com/profile/11145041155115321548noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-27206037976183364852008-01-01T06:46:00.000-08:002008-01-01T06:46:00.000-08:00joe: that's why I said "it makes sense to start wi...joe: that's why I said "it makes sense to start with properties for classes in certain kinds of libraries," specifically libraries for use by others. For libraries and other code for internal use only, that is, the vast majority of code, who cares if you have to recompile; you do it constantly anyway. :)<BR/><BR/>jorn: thanks for the comment; I hope the eclipse plugin stabilizes soon.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-34470620456075563112008-01-01T06:27:00.000-08:002008-01-01T06:27:00.000-08:00A slightly different approach to the file IO examp...A slightly different approach to the file IO example:<BR/><BR/>import scala.io.Source._<BR/>object fileio extends Application {<BR/> fromFile("foo.out").getLines.foreach(print)<BR/>}<BR/><BR/>Using foreach(print) instead of foreach(println) gives me a better result. Though again an example where Scala hasn't quite settled on one approach for a common problem.<BR/><BR/>I'm using the Scala Eclipse plugin which compiles the file on save, hiding the extra compile step from me. I agree that its hardly a "true" scripting language without that tool.<BR/><BR/>About the enumerate method: Yeah, I was missing that, too. Good thing with Scala is that you've got good chances to ask for that an actualy see it in one of the next releases, which isn't too far away. And until then you can just add it yourself with implicit.<BR/><BR/>With posts like yours odds are quite good that Google will have more to find in the future.Unknownhttps://www.blogger.com/profile/11145041155115321548noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-51775516146799818952008-01-01T04:06:00.000-08:002008-01-01T04:06:00.000-08:00In relation to the C# properties, whilst there is ...In relation to the C# properties, whilst there is no syntactic difference, the compiled dll's are unfortunately different and not interchangeable.<BR/><BR/>This means that if you want the flexibility of changing your behaviour in the future, you are forced to insert all the get and set noise into your code.Unknownhttps://www.blogger.com/profile/17914230790959652064noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-71362593521744656262007-12-31T13:26:00.000-08:002007-12-31T13:26:00.000-08:00Not so; scalac complains "error: expected class or...Not so; scalac complains "error: expected class or object definition"<BR/><BR/>I explained in the article why I'm counting code required to make a reusable program, not just code to experiment in the REPL.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-29441926879014736162007-12-31T12:21:00.000-08:002007-12-31T12:21:00.000-08:00Well, you should loose the boilerplate to make the...Well, you should loose the boilerplate to make the comparision fair:<BR/><BR/>io.Source.fromFile("foo.out").getLines.foreach(println)<BR/><BR/>is enough code.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-13972522433551247422007-12-30T23:08:00.000-08:002007-12-30T23:08:00.000-08:00Have you seen Groovy? I would suppose you have, bu...Have you seen <A HREF="http://groovy.codehaus.org/" REL="nofollow">Groovy</A>? I would suppose you have, but potentially worth a look if not.<BR/><BR/>I'm pretty excited about ECMAScript 4.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-22665299752735026832007-12-30T18:47:00.000-08:002007-12-30T18:47:00.000-08:00I've been watching Scala for a time as an "interes...I've been watching Scala for a time as an "interesting language", but I'm beginning to agree with Laurent: JavaScript may prove to be a big winner on the JVM yet. Particularly with ECMAScript 4.Kevin Dangoorhttps://www.blogger.com/profile/13682774192456462795noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-44938857182892885412007-12-30T18:44:00.000-08:002007-12-30T18:44:00.000-08:00To get the convenience of Pythonin a JVM without J...To get the convenience of Python<BR/>in a JVM without Jython, use<BR/>Rhino's JavaScript.<BR/><BR/>No other JVM scripting solution has the of the set of features that Rhino offers and none has a longer track record.<BR/><BR/>Also, JavaScript syntax is close enough to Java. So prototyping in JavaScript to deliver in Java can be profitable.Unknownhttps://www.blogger.com/profile/15165892770802513136noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-11079101234726173562007-12-30T18:03:00.000-08:002007-12-30T18:03:00.000-08:00"drag Java programmers halfway to Python" which on..."drag Java programmers halfway to Python" which only pulls them 3/4ths of the way to lisp ;)Wilkes Joinerhttps://www.blogger.com/profile/16667352630170810773noreply@blogger.com