jump to navigation

Project Euler: Programming (and Math!) Practice November 7, 2009

Posted by ddouthitt in Mathematics, Scala.
Tags: ,
add a comment

As one who loved mathematics (and still do – I considered becoming a mathematician) – Project Euler is a beautiful place to try and get practice on new programming languages as well as mathematical principles. Project Euler provides problems that require solutions, and which are designed for less than one minute solutions using the computer. The problems also highlight a mathematical principle in their solution.

I’ve only worked on a very few problems so far, but it appears that it is quite easy to write a brute force programming algorithm for some of these problems; personally, I am attempting to find the mathematical solution as well as solving the problem in Scala. There is a nice article about one person using Scala to solve Project Euler problems.

The biggest problem in using Project Euler for learning a programming language is that Project Euler isn’t set up for multiple language users: each user is able to specify (and track) solutions in only one language – but this is not a problem really.

If you want to solve more mathematical problems (not necessarily with a computer), the MathsChallenge web site is an excellent one, and is apparently the predecessor to the Project Euler site.

Advertisements

Concurrency October 29, 2009

Posted by ddouthitt in Erlang, Haskell, Scala.
Tags: ,
add a comment

One of the most interesting things about some of these languages (such as Scala) is their innate support of concurrency.

Concurrency is a huge benefit for making systems work together or for making programming systems that can scale (that is, grow and adapt to heavier usage).

Ted Leung at his blog wrote an article about concurrency called The Cambrian Period of Concurrency (and a follow-up). He also gave a talk at OSCON 2009 titled A Survey of Concurrency Constructs which was well received.

Tim Bray, also from Sun Microsystems, created a series of articles on the same topic entitled Concur.next. He talks about Haskell, Erlang, and Clojure. Erlang and Haskell are fascinating, but to me Clojure seems like it took Lisp and obfuscated it and made it harder to learn and use – and became slower besides.

After reading Tim’s article, one of the Glaskow Haskell Compiler (GHC) folks wrote an article comparing parallelism and concurrency. (By the way, not everyone thinks of Haskell when one talks of GHC…)

What intrigues me most about concurrent systems is the ability of multiple systems to work together – not as a cluster, nor in a failover configuration – but as a coherent set of multiple systems doing what each does best. A compute-farm with dynamically responding discrete and unique systems would be one example. Another example (which intrigues me to no end) is a network of servers that responds as a whole to a threat on any one of the servers individually.

Concurrent programming over the network, when used to its fullest, means that a server no longer needs to be the largest unit of response: it means that a network may respond, not just the server. It means that information can be shared among a group of servers rather than just one. Concurrency opens up a vast amount of fascinating ideas.

More Resources for Scala Programmers October 28, 2009

Posted by ddouthitt in Scala.
add a comment

There are a number of excellent resources for those that want to program in Scala – or learn to.

O’Reilly Media recently came out with a book Programming Scala by Wampler and Payne. The real interesting thing is that Programming Scala is also available for reading free online – and it is also available as an ebook.

There is a nice set of slides to introduce you to Scala. There are two quotes in the slides that I just love:

If I were to pick a language to use today other than Java, it would be Scala.
– James Gosling

I can honestly say that if someone had shown me the Programming in Scala book … back in 2003, I’d probably have never created Groovy.
– James Strachan

Scala: Beginnings October 24, 2009

Posted by ddouthitt in Functional, Object-orientation, Scala.
add a comment

Scala is an object-orientated language (similar to Smalltalk) that runs on the Java Virtual Machine. It can be compiled to Java byte-code, which means it will run at compiled speeds.

Scala is also a functional language as well, allowing the programmer to use the same programming methods as languages such as LISP.

In Scala, everything is an object – which is really the way it should be. A lot of “object-oriented” languages don’t subscribe to this requirement – such as Java. Smalltalk, Ruby, and Scala all do – and are sometimes called “pure” object-oriented languages.

The biggest obstacle in learning an object-oriented language is learning all of the classes and methods. Smalltalk makes this easy with a class browser, but languages such as Ruby (scripting) and Scala (compiled) don’t, as there is no way to learn the classes except studying references.

Going from the traditional imperative style to an object-oriented style of programming is not all that hard; it is a one-time “shift” in thinking. It is the classes and methods that require study.

Ruby has a good class reference (both in book form and as a web reference) – and Scala has one for the most recent version 2.7.7 (using the traditional scaladoc format) or one for 2.7.1 (in the new vscaladoc format). It can be also downloaded as a package.