The one things I don’t like about Scala (so far)

The one thing I’ve found so far about Scala that I don’t like is a tendency to have syntactic shortcuts in certain situations that are not very regular with the rest of the language. One example specifically is in the way that you can define a curried function that takes 2 arguments and then call it with the second argument enclosed in curly brackets (“{” and “}”) rather than parenthesis. This seems to be so that you can mimic the look of Scala’s native control structures. However, I believe you can only have one argument (one expression?) in between the curly brackets, which breaks the expectation that curly brackets usually enclose a block. That expectation is set not just by C based languages like C, C++, Java, C# and JavaScript, but also in most other cases by Scala itself.

This breaking of expectation is what frustrates me the most about Scala, because otherwise I really like the language. In general it does a really good job of unifying object oriented and functional concepts, so that semantically it reminds me of a cross between Smalltalk or Ruby and SML. In fact, with Ruby, I think of it as one of the few languages to really get object orientation right. The frustrating thing about the ways that syntactic sugar seems to have been added for convenience rather than coherence is that it’s not obvious why the shortcuts are that much better than the desugared alternatives. Now this criticism isn’t applicable to all syntactic sugar in Scala, some of it is done really well. But there are enough places where it is rough, that it feels like there is a constant slight cognetive load to the language that doesn’t need to be there.

Even though I’ve noticed these little nits, I still plan to keep using it. Overall, I really like the language. I find it’s support for functional programming refreshing, and I think the way it deals with objects makes dealing with them a lot nicer than in C# or Java.

Blathering about blogging

I’m just blathering about blogging today. If I was going to try to do a blog I think it would be valuable to concentrate on doing actually valuable writing. Maybe it would make sense to do about 1 essay per week and then try to post something in the roughly 200 word range each day. Something like 200 words a day and a 1000 word essay per week. Something like that I think could actually be fairly valuable. I still don’t really know what platform I’d like to use for blogging.

I think I’d like to modify my blog layout so that there is a clear deliniation between daily posts that can be just blather and essays and tutorials that should be better written and better written.

Mobile WordPress

I’m just testing the mobile optimized version of the WordPress website to see how well the web based editor and dashboard look on my Blackberry Q10.

I’d probably prefer a native app for the Blackberry, but since there isn’t one currently, I think this will be adequate.

Thoughts on Lua

I’ve been messing with Lua for the past week or so. I’ve been fairly successfully using it to go through the challenges on Code Eval (sea6ear on the leaderboard). So far I really like Lua. I’m kind of a sucker for simplicity and performance, and the abstraction abilities of Lua are pretty good for a language that isn’t Scheme, Common Lisp or Haskell.

However, I’ve used it enough recently that I’ve started to see what are probably the most obvious annoyances. [NOTE: I’ve only been using it steadily for a week, I’m still a newbie. These are mostly first impressions.] Also these are more gotchas than showstoppers, I think once you hit these and are aware of them, you can avoid them.

The most obvious annoyance once you start writing code is the need to explicitly declare local variables. It’s easy to forget and end up with global variables when you didn’t intend for them to be. This is pretty much the same way that JavaScript or Perl handle things, so this isn’t unique to Lua.

A more important annoyance is the interaction between two features that don’t seem dangerous in themselves. Lua automatically coerces values between numbers and strings. Usually that’s something I find convenient. However, Lua’s tables also switch between acting like an array and acting like an associative array (dictionary/map/hash etc) based on whether integer indexing or string based (or other value) indexing is used.

What this means is that you have to be very careful when dealing with data that could be either a string or number and may be used as an index of a table. If you accidentally use it in the wrong format, or accidentally switch between trying to index with an integer vs string format, you will put or try to access data in the wrong part of the table. This can make it look like your data has disappeared when really it’s just been shuffled off to another part of the table that you weren’t trying to use right now.

On a different topic, and really just a minor annoyance, arrays are 1-based instead of 0-based. One based array indexing wouldn’t really be an annoyance except that the rest of the computer world has standardized on zero based indexing (Except for Awk, a language with some similar goals to Lua). It’s not too bad in practice, except when you need to be translating between a zero-based scheme and the one-based scheme.

Overall I really like Lua. I’m really impressed with it. It seems to have almost everything that I want to have in a language as far as semantics. I like that it has tail-call optimization so well constructed recursive functions don’t have to blow the stack. I like that functions can be passed as values. I like (overall) that tables are the central data structure and that you can use them to build all the other kinds of data structures that you desire. I think I will enjoy it’s lightweight approach to object orientation.

I wish that it was more evidently useful as a general class scripting language instead of being primarily thought of as a language for embedded scripting. On the other hand, I don’t want to change it so that it looses that focus. What I’d like to see is a real secondary distribution that had all the libraries to allow Lua to function in cross-platform general purpose fashion. (Luarocks might be that, but I’m not sure how comprehensive it is or how widely it’s used. LuaDist seems like a similar attempt) So basically, I’d like the core distribution to stay small and focused, but there to be some kind of additional library or platform that would allow one to get all the libraries on needed for doing stand-alone work with Lua.

I’m not sure how much work that would be. I’d like to see that happen. I want that enough that I’m willing to work to try to make that happen.

On the other hand, it looks like other people have occasionally tried similar things, and it doesn’t look like any of the other attempts that I saw (outside of Luarocks, and maybe LuaDist?) have gotten persistent traction. Part of that may be that each other attempt at bundling additional functionality has been focused on some fairly narrow niche. I don’t know how much work it would be to create a curated library of various modules that would give you the basics you would need to do real work on various platforms. I’d like it to be something that you would download in addition to the standard Lua download rather than instead of.

I’m not sure what kinds of additional functionality (outside the Lua core) would be necessary for Lua to be able to easily handle the same kinds of tasks that one would do in Python, Ruby or Perl.

Here’s what I can think of:

  • GUI bindings
  • File system manipulation
  • HTTP request libraries
  • Web server capabilities
  • Process interaction and control

Many of these exist in some form currently, but they are scattered and I’m unsure of the level of documentation or consistency of maintenance.

I wonder how many people focused on making it happen it would take to make Lua into a viable language for general purpose computing. I think it could probably be done with less than 20.

I think if I was involved in starting a company I would be tempted to use Lua for the scripting level (along with C for low-level, and Erlang for very high-level tasks) in hopes that the company could contribute code to making Lua a viable language for general use outside the game industry and niche areas. Even though Lua wouldn’t be as useful as Python or Ruby starting out, I think it would be worthwhile to focus on it and make libraries that did enable it to be used in a wide range of areas.

Lua could also use some more beginner oriented books. Programming in Lua is awesome, but it’s a pretty advanced text in terms of the language concepts it deals with. I would be interested in writing one of those beginner books once I am more familiar with it.

It’s been almost a year since my last post. I’ve been journaling mostly offline for a while. I’ve been trying to write 1000 words a day each day. A lot of the time I achieve that, some days I don’t. But I haven’t been good at going back through my writing to pull out things and put them up here on the blog. I’d like to start doing a better job of that.

Language Choices

I think that if things were up to me I’d have one list of languages that I concentrate on for continuous study and application development, and a list that I bounce around in for fun and study and making toys and stuff.

The core languages I’d concentrate on for continous study and industrial application development:

* C++
* Perl
* Common Lisp
* OCaml

The languages for prototypes, utilities, fun, exploration and experimentation:

* C
* Lua
* JavaScript
* Scheme
* Tcl
* Smalltalk
* Forth
* Prolog
* Erlang
* Awk
* Assembly

I think the core languages are strong enough that any of them could be used for almost any task,
but there’s enough flexibility in the list to pick a good match for any particular use.

I’d use the larger list for single purpose apps and experimentation. Each of them is small enough
that I think I could get into a partincular language for a month or so and either learn something useful
or develop something small but real using it.