Sunday, May 5, 2013

Suomi Öljyn Jälkeen (Partanen, Paloheimo, Waris)

My review of a new book, in Finnish. "Finland After Oil".


Mainio kirja.

Olen sivulla 246 ja vasta nyt alkaa kirjan itsensä niminen luku, "Suomi öljyn jälkeen".

Tähän asti kirja on kurvannut läpi energiahistoriamme ja sen erilaiset umpisolmut. Varsin hyvää, luettavaa tekstiä, joka toisaalta menee riittävän syvälle saadakseen lukijalle ahaa-oivalluksia, mutta toisaalta ei jää pureutumaan yhteen näkökulmaan tylsästyttävän pitkäksi aikaa.

Samoin kirjoittajien tyyli on mieleeni. Asiat sanotaan suoraan - esim. Venäjään liittyvää analyysia oli miellyttävä lukea, mukaan lukien itselleni uusi sana 'kleptokratia'. Kirjoittajat ottavat asiat henkilökohtaisesti ja kiertelemättä, mutta osaavat samalla pitää asiallisen etäisyyden ja perustella väitteet numeroilla tai muuten mielestäni riittävällä analyysilla.

Jonkinlaista turnausuupumusta on tässä lukijassa jo havaittavissa. Tyyli tietenkin toistaa vähän itseään ja ongelmia löytyy - yllättäen - enemmän kuin ratkaisuja. Ensimmäiset 150 sivua menivät ahmimalla, nyt viimeisten 50:n kanssa on niin ja näin. Toisaalta kappaleiden pituudet ovat koko ajan olleet mukavia. Juuri kun yhdestä näkökulmasta on saatu käytyä läpi kaikki olennainen (jonka tämä lukija jaksaa omaksua), esitetään jatkoksi jotain vähän erilaista ja taas mielenkiintoista.

Pidän jollain sairaalla tavalla romahduskirjoista. Jos sitä joskus epäilee, että ihminen on todella tyhmä, nämä antavat sille perustetta. Oikeastaan tekevät luulosta tiedon. Joukkona me olemme äärimmäisen tyhmiä. Kuten kirja asian esittää: millään muulla eliöllä ei ole järkeä tuhlata tällaista energiavaraa. Ei kyllä meilläkään. Evoluutiomme taitaa lopettaa itse itsensä.

Kirja mielestäni tarvitsee kumppanikseen vielä toisen, joka näyttää enemmän valoa ratkaisuihin ja luo mahdollisuuksia täynnä olevaa tulevaisuutta. Olemme aiemminkin pärjänneet tiukissa paikoissa, ja meillä on edelleen tieteemme tukenamme. Kriisi lieneekin enemmän poliittisten rakenteiden aikaansaama ongelma - ns. "demokratia" etunenässä. Lukiessaan tällaista kirjaa alkaa väliin huokailemaan suunnitelmatalouden perään, mutta ei sekään olisi vastaus.

Jos jostain en oikeastaan ole pitänyt, se on kirjan nykyinen kansi. Tuo ei mielestäni kuvasta kirjan paljon laajempaa sisältöä ja analyyttista mutta luettavaa asennetta. Likainen öljytynnyri vie koko kannen. Ehkä parempi olisi ollut kuva jostain suomalaisesta, jossa tynnyri lojuu tyhjänä ja tarpeettomana sivussa (toisaalta tuulimyllyjä jne. aikalaiskliseitä pitää välttää).

Upea kirja! Hieno lukukokemus!

Nyt hoitamaan tästä käännöstä ruotsiksi, englanniksi ja ehkä ennen kaikkea venäjäksi ja kiinaksi.

Ja samalla sitä ratkaisukirjaa...

Julkaisija: Into Kustannus, www.intokustannus.fi
ISBN 978-952-264-196-0

Tuesday, December 18, 2012

Adding 'condapply' to Scala, for natural JavaFX bindings

The Scala programming language is wonderful, and if anything, it suffers from a little bit too many tweaks and shortcuts (access syntactic sugar).

But here's one more suggestion.

The particular itch is that JavaFX bindings that in some languages can be expressed in a normal if/else:

  def z = bind if (b) then x else y;

 cannot be created so nicely in Scala (or in Java, for that matter) - since if and else are keywords.


  def z = when (b) then x otherwise y;

This is how the current ScalaFX library does it.

Since Scala is a very powerful language, I began to toy with the idea, how it could allow the "natural" binding syntax for ScalaFX. And - I think it can (well, not the current Scala, but it could be added).

Existing apply and unapply

Currently (Scala 2.9) Scala has methods called apply and unapply, which are called when i.e. a function call is invoked on a class. The compiler transforms the (...params...) of the call into a apply(...params...) call for the class. This is very, very common in Scala.

The unapply is used less seldom, in pattern matching (in case you want your class to support this amazing feature fully). Normally classes don't need to do that much (one can use "case classes" that do it automatically).

Anyways, this provides a precedent as to methods where the compiler transforms its syntax into bendy method calls.

Introducing condapply

I would like to call this cond, but that would probably be a bit too common, and it would lose the mental bridge to existing (and well understood) apply and unapply methods. So let's say it's condapply.

  def condapply[T]( t: => T, f: => T = null ): T

That's Scala prototype for a method that takes two "by name" parameters (that simply means, they will be lazily evaluated; only one of them). Both the parameters are expected to provide the same type of value (T), and the method itself will return this very type. If no else branch exists, f will be null.

What ScalaFX could do with this, is to have the Observable trait implement this method, and therefore make Observable's applicable within an if. What the implementation would do is bind that Observable to the two branches t and f (mathing then and otherwise in JavaFX API).

By the Scala prototype the branches would not need to be of the same type as the condition, but here they happen to be.

For cases where there is no else branch, the Scala compiler would create a condapply call with just one parameter. It would be up to the class to catch both cases (either using two separate prototypes, variable argument list, or default parameter for the latter parameter).

The benefits

The suggested addition to Scala would allow conditional bindings to be expressed in the usual if/else syntax, s.a.

  def z = if (b) x else y

It will not render any existing code invalid, since currently the if statement is limited to conditions of type Boolean

Whether it will make code more readable, and easily understandable, is a matter of opinion. Personally, I would probably use it, but also something like:

  def z = bindIf (b) x bindElse y

is quite okay (and can be done without changes to Scala).

Other uses

There may be other uses to the presented technique outside of ScalaFX.

Thursday, November 8, 2012

Oracle - how to be More Believable on OS X

Recently, the baton on Java on OS X was passed from Apple to Oracle. From Java 7 onwards (i.e. now), updates come from Oracle. Also, integration with operating system has changed in various ways.

Most of this is good.

And then there's this.



Instead of nicely integrating the Java Control Panel into where the rest of the settings are (i.e. within the topmost window), Oracle chooses to launch the one below.

There's a plethora of user interface issues here.

1. "About" is topmost on the Control Panel window, on the first (default) pane. It's the *last* thing a user needs. Move it!

2. It simply looks Bad and Boring. This is not in line with the coolness that JavaFX tries to bring to Oracle. Put some meaningful graphics on the first pane?

3. *All* of the four buttons on the first pane have "..." in their captions, meaning you can do *nothing* in this pane alone. Too deep organization.

The reason for this, of course, is that they want to run the Control Panel in Java (it looks just the same in Windows). That's probably a valid excuse for the first OS X version. Not for the long run.

So let's fix this. :)

Don't launch anything new, make things fit in the OS X usual Control Panel (hire some consultant to do it in Objective-C, it's not contagious).

We can probably use the same tabs, but some would benefit from a renaming. Let's check them one by one (sorry that I haven't made any UI sketches on this - have other things to do):

General tab

Drop the "About" from here (moves i.e. to under "Update" where it's more relevant).

Drop "Network settings are used when making Internet connections." *Anyone* (anyone who found the Control Panel, anyways), does know that. Less is more and this simply makes Oracle (the boss within Oracle who demanded this text) look Stupid..

Since you're saying "only advanced users should modify..." why exactly is *this* on the front page, then?

Pressing 'Network Settings...' gives:


This should imho be a "Network" tab of its own, just prior to the "Advanced" tab. You said it yourself. For advanced users. = moved.

Temporary Internet Files has the same "only advanced users should".. mention. By having these right on entry page of the Control Panel you make the occasional Java users (who are millions) think Java is "only for advanced users". Unnecessarily. Move this, too.


There's enough in there to grant a separate, top-level tab (within the real OS X Control Panel area). Let's put "Temporary files" (or "Disk cache") before "Advanced".

Then there's the "View..." dialog of the initial page (yet one very advanced thingy).

Or actually, it turns out to be almost like a separate application within the Control Panel (which is within the OS X Control Panel). Way too deep - I bet most people never knew this even exists? I did not. :)



It's three things.

"Applications" shows which apps are taking disc space for their cache files. This is great, but... the icons on top allow one to i.e. launch these programs and look into their source code. Someone in charge of this wanted more than one icon, and got it. *Completely unnecessary* within a Control Panel.

Let's make this into a "Cache" tab (for brevity) and just keep the possibility to list the apps and remove their cached data.


"Resources" has things that come from the Internet. Maybe it can be selected like above (show) but maybe the two lists could be put in one, i.e. Apps on top, followed by Resources. 


"Deleted applications" is completely unnecessary. Someone in some meeting wanted to play safe and duplicate a trash bin. Don't Do That. Stick to simplicity. Though Java (well, JVM) is gorgeous, you don't want it to explode on people's faces. They already have enough stuff to take care of. One can always re-install an app from the original place. Trash.

That covers the first, "General" pane, and - nicely - nothing remains on it. I would claim that the proper title for the pane should have been "Miscellaneous" since these really were things that didn't fit anywhere else. Too bad they were placed on the *entry* place of the Java Control Panel.

Update


What a waste of empty space.

Merge this with the "about" popup that comes from the General tab. 


I would bet that the *most* frequently used feature of Java Control Panel is to check which version you are running and possibly upgrade. Make this the entry page (it already has the nice graphics). Don't hide it behind an "About.." button.

That covers the "Update" pane, which now functions as the nice entry page within the Control Panel.

Java

It's kind of awkward to have a "Java" pane within a "Java Control Panel", isn't it? If this pane is "Java", what are the others?


Again, you probably noticed the (lack of) use of empty space, and making people push yet another Button... (A copy of this pane alone would make for 15 minutes of teaching at a University Usability Course - if people would learn by bad examples, which they don't). :)

Ok, let's be humble and press the "View..."


There comes "Java Runtime Environment Settings".

Let's forget about the unnecessary interim "Java" tab and call the tab "Runtimes" at once.

However, knowing that in the Oracle way of distributing Java for OS X there is only one runtime at any one time, I wonder what's actually the point of all this. Apple had a similar list where one could manage multiple Java Runtimes. Oracle itself has said this was a very, very bad idea. So .... what is this for?

Security


"Use certificates to positively identify .. certifications." Yeah, right.

- empty space
- button...

Just call the whole page "Certificates", and have this (what pops up by pressing the button) right on the topmost level:


Certificates is probably an even more advanced issue than Network and Temporary Files and therefore deserves to be listed after them.

Advanced


This can probably remain pretty much as-is, since the name anyways implies you should know what you're doing. A tiny help pane on the right side for getting info on the settings might not hurt (especially since the OS X Control Panel would have more horizontal page available).

Maybe reduce the font size a bit. It's advanced. There are many options. Smaller font size means I can get a better overall view at once.

Altogether, now

So the current (Oracle Java 7 SE) Java Control Panel organization is like this:

General
   About...
   Network Settings...
   Settings...
   View...
Update
Java
   View...
Security
   Certificates...
Advanced

The proposed flatter organization is:

Update
Network
Temporary Files
Caches
Runtime   (if required)
Certificates
Other

Since essentially all the entries (except for 'Update') are advanced (already declared so in the current Control Panel implementation), it is probably in place to re-title the earlier "Advanced" as "Other".

The Theory

I've developed a theory (mainly by observing XBox/Zune and other Microsoft mess-ups) that the internal structure of an organization is traceable in the software it produces. That is, unless a special effort is taken to smoothen such borderlines from the eyes of the user. I bet that the issues mentioned above are not coming from developers. They reflect something within probably Sun and not Oracle that caused this kind of approaches to be taken. It is sad if such usability failures are allowed to live further over the years, since *this* is what most people will feel when they touch Java. Is it flat, easy and good-looking. Or is it unnecessarily structural, hard to handle, and aging.

Oracle, please decide.

Wednesday, October 31, 2012

An IDE for ScalaFX development? Yes - PLEEEEEASE!

This entry should tell you how to get an IDE (Integrated Development Environment) up and running for Scala development - and especially for ScalaFX (graphics application) development.

It shouldn't be even this difficult (and most likely will become easier over the years).

The *current* (Oct 2012) situation is that I fought over a week with Eclipse Juno without still getting it to fully work. With IntelliJ the fight was roughly half a day (not bad). 

With this text, you'll be up and running within an hour.

You shall need:
- OS X
- Scala 2.9.2 installed via HomeBrew.
- ScalaFX jar precompiled

You probably should read this earlier blog post first.



- Download "IntelliJ IDEA". Use the "Early Adapter Program" (recommended for Scala plugin to work) and take IDEA 12 (it has a great duck splash screen):

http://confluence.jetbrains.net/display/IDEADEV/IDEA+12+EAP   ( I took version 'idealC-122.639.dmg'. )

- Drag 'Leda-IC-122.639' app to somewhere (i.e. /Applications).

- Launch it and pick 'Open plugin manager' (top right corner of the welcome page):

- "Browser repositories…" > choose "Scala" plugin (v.0.6.287) (double click to download & install)
- You may also wish to install "SBT" plugin but it seems to only provide compilation help, not sure how it can be used for debugging.
- restart IntelliJ

THIS IS IMPORTANT!!!

In order to use the Scala plugin, it needs to be given a "language facet", essentially libraries that tell where Scala compiler & libraries can be found.

We'll do it here using the command-line-installed ("brew install scala") version 2.9.2 files.

- Create a project (i.e. from scratch)

Select type: "Java module"

Click "Scala" on the "desired technologies" page (below) and fill the "Create compiler library" and "Create standard library" names to your liking (and probably you want them to be 'global').

We'll make these point to the right HomeBrew-loaded jar's in a minute.





You should get to the main IDE soon.


There's a ton of things you should go through in File > Project Structure… Do it now.

Within there, you see 'Modules > Scala' that should be like this:


Notice that "scala-compiler" is selected as the way to compile Scala. This points to the scala-compiler.jar and scala-library.jar that we'll now define under "Global Libraries" (last entry of the "Project Structure…" dialog):

Make the entries look like this (in case you do have Scala 2.9.2 via 'brew'):




This should allow IDEA to compile Scala. 

NOTE: It is absolutely essential that you only play with one version of Scala. Don't download "another" 2.9.2 and make IDEA point to it (did not work - at least not for me).

- Within "Project Structure… > Libraries" add 'scalafx-1.0-SNAPSHOT.jar' (that you've snitched earlier, compiled with the same Scala version):


- To compile, "Build > Rebuild project" (I'm not a fan of automatic build)

- To start code, right click i.e. on 'Main.scala' and take 'run MainFX.main()' (no breakpoints etc.) or 'Debug 'MainFX.main()' (will stop at breakpoints).

Did it work?

Note that i.e. renaming the "Scala compiler library" seems to be enough to throw the "Scala facet" setting off the wall, and requires it to be reset ("Project Structure… > Facets)

References:

http://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin


Saturday, October 20, 2012

Replicator service for spare parts, anyone? (mail order, reasonable price, scanning included)

I broke a small part of a classic table lamp recently, and am now considering the options of how to fix the damage.

Glue will probably not be strong enough. Wood will take time and not be 1:1 with the original.

Are there any 3d-printing shops available (within Finland, EU or globally) which would also offer the necessary scanning for actual replication of existing parts?

Ideally, they would extend the missing part, and give me perfect holder piece that lasts the next 40 years.



We thought this was science fiction. Star Trek has it. But the technology is there, and the business model is simple. I'm sure there's someone already out doing this - please find me. I'm your customer! :)

Contact either by comment here, email to akauppi(at)welho.com or twitter @bmdesignhki.

Addendum.

Got the parts done, in bright Xmas Red. Lamp says Thank you, Robin B!





Wednesday, October 17, 2012

Getting ScalaFX 2.2 demo up and running on OS X (with Oracle Java 7u7)

News 20-Oct-2012 - JDK 7u9 and a JavaFX 2.2.3 samples are out:


Use those files instead of the 7u7 mentioned below. The performance of some JavaFX Ensemble demos is now way better on the NVidia 9400 GPU (but not all). Also, there are new demos included in the bundle.



JavaFX is a 2d/3d GPU-accelerated graphics library that is going to be replacing the Swing as the main Java application UI library.

ScalaFX is a Scala language binding to JavaFX.

JavaFX development kit is distributed as an integral part of the general Java 7.x development kit (JDK), by Oracle.

Below are the steps to get a basic ScalaFX project started, developing on OS X.

You will need:
- OS X 10.7.3 or later ("Lion" or later) (a JDK 7u7 requirement)
- Basic experience on command line usage on OS X
- HomeBrew (or similar) command line tool installation system ('brew' is great and easy to install)
- Willingness to accept the Oracle 7.x JDK license agreement



Getting ScalaFX and JavaFX 2.1 running on OS X

Java SE 7 Update 7 (or later)

Download and install "Java SE 7u7" (or later) from Oracle:

Take these files:
jdk-7u7-macosx-x64.tar.gz
javafx_samples-2_2_0-macosx-universal.zip

The JDK (development kit) contains the JRE (runtime engine) so just a single install is sufficient.

Installation FAQ:

Note for users with Apple Java 6:

JDK 7 Installation for Mac OS X:

In short, just install the .pkg file by double-clicking. It will not replace the Apple Java 6 (in case you have Java enabled). You will need Java 7 for JavaFX 2.2 to function on OS X.

<<
You can determine which version of the JDK is the default by typing java -version in a Terminal window. If the installed version is 7u6, you will see a string that includes the text 1.7.0_06. For example:
    % java -version
    java version "1.7.0_06-ea"
    Java(TM) SE Runtime Environment (build 1.7.0_06-ea-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)
To run a different version of Java, either specify the full path, or use the java_home tool:
    /usr/libexec/java_home -v 1.7.0_06 --exec javac -version
<<

JavaFX samples

Likely you already downloaded these (see URL and filename above).

Extract the files to some suitable directory.

To launch the .jar files, right-click and select 'Open in Jar Launcher > Run (or Open or something)'. This seems the way to bypass safety system preventing to launch .jar by a simple double click.

On OS X, they don't (yet) support launching from the HTML files. Ignore them. )

The UI responsiveness may be sluggish at times. This may be because of lack of optimization for hardware (GPU) rendering. Oracle site says any GPU supported by Lion should do, but in practice my MacBook Air (integrated Core i7 Intel GPU) performs way better than 2009 Mac Mini with NVidia. Likely the situation will improve once Oracle gets more OS X tuning done. Hope so.


BrickBraker.jar

Nice retro game.



Ensamble.jar

Try making this into full screen mode (the '+' icon at upper right). Unfortunately it seems the 'real' full screen mode (Apple-F) is not supported by JavaFX (or this demo)?

The 3D-xylophone was probably hot in (…no, it never was). Now it mainly displays the lack of antialiasing in its rendering.


"Advanced media" demo looks like animated gifs when played in full-screen on my Mini (but good on MacBook Air).

"Audio spectrum data" demos are great - check the lyrics! :)

The song is available also in Youtube.


ScalaFX compilation


First, get 'hg' (Mercurial) and 'sbt' to the Mac (i.e. using HomeBrew):

    $ brew install hg sbt

This makes a copy of 'scalafx' repository (to local folder 'scalafx'):

    $ hg clone https://code.google.com/p/scalafx/

The instructions in  'README.txt' are outdated. Do this instead:

    $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/
    $ sbt clean compile package

(without the 'package' sbt does not create the target/*.jar file)

To launch a demo of fading circles (makes other things on your computer crawl so don't leave it on :) ):

    $ sbt run





Making your own project

Create these files:

    build.sbt
    lib/
        scalafx-1.0-SNAPSHOT.jar
    src/
        mydemo.scala

'build.sbt' you can adopt from the one used in ScalaFX samples.

'lib/scalafx-1.0-SNAPSHOT.jar' is a copy from the 'target' directory of scalafx compilation.

'mydemo.scala' is whatever file you wish to use (again, something from the scalafx 'demo' directory would be fine).

    $ sbt run

Please make a comment if you got things working, with this walkthrough.


Monday, October 1, 2012

iPhone Lite - Yes, They Should!

"Analysts" are telling this:

http://appleinsider.com/articles/12/10/01/apple-seen-as-unlikely-to-introduce-new-inexpensive-iphone-model

I'm telling Apple should introduce an iPhone Lite and here's how I would have it done. Heh, writing's Cheap! :)

In the new iPod Nano, Apple has introduced a form factor that also suits a phone. 7.6 x 4 x 0.5cm. You can fit three of those on a Samsung Galaxy III (almost; that's 13.7 x 7 x 0.9cm).


Ingredients to add:
- GSM/EDGE telephony (no 3G necessary)
- iMessage
- Twitter (with pictures)

That's it.

Since the device is so small, one can think of using it with earphones only (the same as currently).

Having such a wide gap to the existing entry-level iPhone 4 makes a clear differentiation between the models. At the same time, this makes iPhone Lite perfect as a child's phone. Or as an entry level developing world phone (Brazil et.al.) without tarnishing the Apple brand.

Apple already has this division between iPhone and iPod touch. They only lack a phone in the Nano size category. It should look *exactly* the same.