Tail-recursive tree traversal example in Scala

This is a demonstration of a tree-traversal algorithm to calculate the size of a binary tree, in Scala. The two implementations are recursive, as one should try to do in functional programming, but the first implementation is not tail-recursive, and the second is.

Continue reading

Nokia N8 review: software

This is a second part in my Nokia N8 review. I already talked about the hardware in a previous post. It’s safe to say the hardware of the N8 is admired by most people. Some specs are relatively modest compared to some competitors, but that results in a more accessible product. The phone is also more than one year old, and even Nokia itself has already released phones such as the 701 with faster CPUs — 1GHz and 512MB of RAM in the 701 instead of the 680MHz and 256MB in the N8.

On the other hand, the Symbian operational system that comes in N8 receives a lot of criticism, but not always justified. In this part of my completely personal review I will talk about the software, what do I use, what do I miss.

I should remind the readers that I am a nerdy programmer, a fan of command-line interfaces, but I do appreciate good graphics when they are needed and/or well done. One first thing I would like to say I miss in Symbian is precisely this, a command line interface!

Shell (i.e. a command-line, a terminal): This may come as a surprising comment for many. But here is one feature that is very much available in Maemo (and also N9’s Harmattan), and also available in Android and Iphone (at least with the necessary apps or jailbreakings or whatever. I don’t know very much about these platforms.) I really wish I had an N9 or N900, and I used to have a N800, but I got an N8 for the lower price and great camera, but also because I wanted to start coding Qt apps for Symbian. Qt is what these platforms have in common, but if there is one thing that is different in them is this: while Maemo and other Linux-based OSes came from the desktop world, not to say mainframe world, Symbian is native to the mobile world. So what my desktop coder mind understands as an omission, any 1980s or 1990s mobile developer would just consider madness.

Will Symbian ever grow to support this kind of things and make someone like me feel more at home? I don’t know. Making the system open-source would be a great step to that direction, but that didn’t happen yet. Let’s see what the future reserves.

Symbian has had Python ported to it, though, and that means a Python shell along some basic utilities that you would expect in a more general shell. That project was quite active three years ago, but there were no updates since then, and after so many earthquakes in the Symbian planet I have no idea where the project is going, and I never got to play with it. It does seem that you can install all the stuff and play with Python on the device, I must try that some day.

SSH: While there is no shell available, there is one important application of CLIs that is thankfully covered in Symbian. That is connecting via SSH to a remote machine so you can get things done remotely, and on the move. For any coder or system administrator that can access machines via SSH, it is great to be able to log into your machine to perform simple tasks like running a test, copying some file to download from a HTTP server, or whatever.

The application that allows you to do that is unfortunately not available in the Nokia store, and is PuTTY. This is the “Touch UI” edition, to be used in N8, updated from the S60 PuTTY. It worked great for me, and I was very happy to be able to log into my machines with my N8, coming from my N800.

Be aware that there is something called PuTTY at the Nokia Store, but it’s not the real thing. They are just making use of the name, very much wrongfully if you ask me.

Basic stuff: There are three home screens where you can put 6 fixed-size widgets, automatically re-organized for landscape orientation if you rotate the phone. One of the widgets is an application launcher that can hold 4 icons. Many applications work in the two orientations, something I guess was a special concern because of the E7 with its keyboard.

You can switch between the screens with either a button, or swiping. Before the Anna update it wasn’t a neat dragging of the icons, but that changed, so you can be happier if you think this matters. Myself, I am much more concerned with the fact you can switch cyclically between the screens, for instance. One thing I dislike though, is that the backgrounds are simply different images. I like very much the “parallax scrolling” effect in Android… All my wallpapers are images that I cut by hand in three to use as the background of each home screen and make the image “span” the whole virtual desktop.

Using the button below the screen you can call a menu to launch applications, which obviously supports recursive folders for you to organize everything. A long press brings the list of running apps for you to switch or close. Pressing the button can become quite tiresome, and I would very much like if the system supported N9’s swipes…

By the way, the system can frequently hang and let you holding the button like a dork trying to switch between applications, for example. I get impatient sometimes and go pressing “back” or “cancel” buttons, only to be suddenly taken to the “Call” screen, then “Exit”, and I get veeery angry. I have no idea who’s to blame, if the slow CPU or the software. Word on the street is that Belle improves the situation a lot, and making a clean install of Anna can also help, but I haven’t tried either.

Clock and calendar are cool. They could be more sophisticated, but I can live with it. What I do like a lot is the screen-saver clock, which also has notifications of SMS messages and missed calls. Gravity also notifies new messages there. There is also Nokia Sleeping Screen that offers lots of pretty graphics for the lock screen.

While these notifications at the lock screen are good, I really miss a notifications bar like in Android. There are pop-up windows that show up sometimes, in the top and bottom. They print out just half of the first line of SMS messages, for example, then vanish. Not very sooo useful.

It seems Belle has some kind of notifications bar. I am looking forward to use it. On Anna the top bar does take you to USB connection settings, battery information and other things.

E-mail: The e-mail client is quite good for my use. I use Gmail via Mail for Exchange. Some people complain about not being able to use more boxes, etc. I’m sure it could be improved in a lot of ways, but for my basic usage it’s totally satisfactory.

The store: Maybe it’s time to talk about the Nokia Store. That’s where Nokia puts approved applications for download, along with a few by Nokia itself. There are lots of apps, categorized into Games, Application, Audio & Video, etc. Some are free and some are paid. After you enter your data, it’s pretty easy to buy the paid apps. There are also user reviews, and you can easily write your own. There is a native client, and a webpage. All pretty much like any other store, I think. The native client is new, a great improvement from the original one.

Contacts and Social: There are lots of integration of the system with social networks. This can be improved, but is a great beginning. You can very easily share a picture via Facebook and Twitter from the image gallery or the camera app after taking a picture. You just press the “share” button, write a caption, and that’s it. Very easy. If anybody tells you different, it is a lie, plain and simple.

Nokia’s Twitter and Facebook client is a bit slow, but I used it for a while, until I moved to Gravity. I only really liked its widget. I think it’s written in WRT, if they came up with a Qt version it would be great.

There is also some integration of the social networks and the contacts. But I never really exercised that…

Browser: The browser is not perfect but is getting better… There is Opera and UC browser too. I have tried them, liked and disliked and eventually got back using just Nokia’s. I keep hoping some update will make it faster. the one thing that keeps getting to my nerves is that pages don’t get automagically reformatted so you can read it properly on the phone screen.

This subject probably deserved an article for itself…

Music player: I only started using it for real recently, because I was using Spotify all of the time. It’s pretty basic, but I don’t have any major complaints so far. I like the “cover flow” animation very much, it’s 10.000x better than Apple’s. The Ipod cover flow actually makes me sick, gives me some kind of vertigo. I much prefer Symbian’s.

Widgets: The widgets I use today are the Clock+profile, missed events+messages, wifi, favorite contacts, vlingo, e-mail and calendar. I used to have some RSS news too, but it only display the beginning of the news titles, so it’s not very useful. They also don’t reload automatically very often. By the way, this is something in the whole system that makes me mad. Much more often than not, applications are designed to use as little the network as possible. And you can’t flip a switch that says “I don’t care, I have unlimited connection, I am on Wi-fi…”. So I am often thinking “why won’t this simply go and do these things automatically??…” That would happen on the social client too.

Now I will talk about some available applications that I use. I only talked already about PuTTY. There is a lot of people out there talking about the number of applications available in each platform, but while I hear a lot of statistics, I hear very little about the applications themselves. It would be nicer if we always had in mind what is missing in each platform, and try to look for the reasons for developers not having been attracted to solve the omissions.

I remember that Foursquare for example did not have a client for Symbian for a long time. Eventually it came up. But now it seems the service is not so hot anymore, at least in America. I do use it…

I use Nimbuzz for Google Talk, and it does its job when I need it. I use Skype for voip, and I have used fring a bit too. I never tried much video calls, so I can’t talk about that. I don’t know anyone who likes playing video-call! 😦

Symbian also has native support for VoIP using SIP servers, that I mentioned in the other article. It’s annoying to set up, but works very well afterwards.

Gravity: This is a very celebrated Symbian app, and I ended up _having_ to buy it. If I am to defend Symbian, I must know its greatest apps! It is a really nice client for Twitter, Facebook, Foursquare and other social networks. I wish the widget was better, but I don’t have many complaints after that. I use it for sharing images too, when I don’t use the native tool.

Games: Sometimes you read an article by American tech journalists (Engadget and The Verge, I am looking at you and using your expressions), and get the impression you will enter Nokia’s store and see just a handful of crappy games. That’s BS, there are lots of cool and awesome games to be played on the N8.

It has Angry Birds, that at least one or two years ago seemed to be the definition of what constitutes a Smartphone. There are other classic touchscreen games too such as Fruit Ninja… There is Tetris! The late 1980’s Angry Birds of any computer or video-game was Tetris. So I made sure I got EA’s version of the game. There are lots of other cool titles like Need For Speed Shift HD. I haven’t tried yet, but reviews are positive and the graphics look great. In the 3D category there’s also Assassin’s Creed and others.

That all goes to show the N8 and Symbian is perfectly on par with other devices out there. And there’s plenty of games available. I just gets crazy when people start talking about how many hundreds of thousands of games are there in different stores. But the reality is that lots of cool games are available in all stores, and are available for Symbian as much as for other platforms. So don’t let the pundits make you believe that you will be alienated from cool games if you buy the N8 or other Symbian phones. You will not!

Some other games I have right now that I like, not in the 3D front: There is Warspear, that is a cool MMORPG with simple Final Fantasy style graphics — but I haven’t had much time to play that lately. The Tron Tanks game is very cool, the graphics are very amazing, and there are other tank battles games, I don’t think they are very fun to play actually, but I think I would find the same in any other mobile phone out there. I recently got this couple of puzzle games that are very cute and funny, Antartica and Doodle Fit. This last one is very beautiful and simple, it’s really cool… Neon Mania is another pretty game, quite childish actually, but nice to see because of the pretty graphics.

I can’t tell if I am in fact “riding the wave” of the contemporary mobile apps and games, and you can’t avoid to question with so many people screaming out there about the pure and exclusive joy of having an Ios or Android device. But I certainly have not been feeling that something is missing. A very cool game that came up some time ago, developed in the Brazilian offices of the Nokia Technology Institute (INdT) is Incredible Circus. It is written in Qt, and is very fun and pretty. You can get mad if you play this game, and then right afterwards you read about people saying Symbian sucks because there are no fun games. The realty-distortion field against Symbian can get so strong sometimes.

Having fun with games must not be about having 100.000 different minimally satisfactory titles available for you to play. Swim in a cornucopia of totally different stuff, always moving to the next title. I am sick of the distant attitude of judging the platforms based on impersonal statistics of number of available apps, or downloads or whatever. We should be talking about what do we like and do, what we have been playing and using. The only mobile game that ever truly became a conversation topic everywhere was Angry Birds. And that is available everywhere already. Other than that, discussions always migrate away form the true content, into “meta-content”. And that sucks.

So yeah, “games, games galore” in Symbian!… If you need more games than that, I am pretty sure you are not an “average user”.

Maps: There are two map applications I use in my N8. Nokia Maps, that is great for the ability to do some stuff offline, and Google Maps. Google maps is specially important for me because it has public transportation info, that Nokia still doesn’t offer — but they are working on it. It connects to Google Latitude too. Anyway, all that pretty much satisfies my needs, I don’t think I have any specific complains or compliments worth mentioning…

Maybe turning on the compass from inside maps. You must “flip” the phone. Sometimes it simply doesn’t work, I keep flippin’ the friggin’ phone, and it doesn’t turn on. Really upsetting. I am also upset because I never got the feeling the true, satellite-based GPS ever worked for me. I never could locale myself somewhere I did not have a network signal. But that has been my experience with other smartphones too.

Camera stuff: I got Camera Pro, mostly because it lets you save images with 100% quality, and the digital zoom goes further. I haven’t really made use of its other functions, though. I didn’t have the time…

The video editor as a bit of a disappointment to me because I tried to stitch three large clips together, and the audio got out of sync. But for basic editing that the “normal user” will probably want to do, it seems it’s great. I don’t do much video. The image editor too, seems quite basic to me. I never usually edit an image unless I am going to do something fairly complicated.

One application that is quite cool is Nokia Panorama. I work with computer vision, so I was very much attracted to it. The camera tracking is not perfect, but I have created a couple of very cool shots already, so I am quite happy about it.

QR-codes reader… I have been using MobileTag. It could work better, it’s my feeling. Too much hassle for something that would be simple. But I think part of my negative experience is in the somewhat slow browser, and turning on the camera itself is always a bit slow too. So I am not sure how much such an app can be guilty. It solves my QR-code needs though.

Connectivity: Two apps I could not avoid mentioning is JoikuSpot and SymFTP. JoikuSpot creates a a Wi-Fi network,in ad-hoc mode, that you can connect to with other devices (ie. your laptop). Works pretty well, and you can set up a password, only in the paid version, I think. This apps was a pioneer in the field, and I am happy to support it.

SymFTP is an FTP server, and appears to be a fairly recent application. I got it looking for easier ways to move files to and from my phone, and it worked well.

Symbian also has a native WebDAV client, completely integrated into the file system, what was supposed to be awesome. The problem with it is that it appears to have limit in the file size to be transferred, something around 1MB. I am very much disappointed with that, and I wish there could ba a good explanation why it doesn’t work properly. Or better, it should work properly! Anyway, when it works I am able to connect to a server I installed in my notebook, but also to SMEStorage, and to an Amazon S3 bucket.

There’s an USB media transfer thing too, but I never used that.

Vlingo: I confess, I only started using that because of Apple’s Siri. I am sure it’s not yet as much integrated into the system and other apps as Siri is, but it could be with some more effort from all the companies involved… I kind of liked to use it sometimes. But I don’t really see myself talking a lot, I am not usually very talkative, unless we start arguing about e.g. the global smartphone market.

It should also be mentioned that there is voice recognition already in Symbian for ages, for making calls. But I almost never call anyone!

Nokia Internet Radio: I use that every day to listen to local news at CBN. It’s quite hard to pick up FM radio here in São Paulo, so Internet streaming is definitely necessary. and it also avoids having to plug the headphone in. I love it. I also listen sometimes to WFMU Ichiban Rock & Soul, and New York’s WBAI and WUSB.

Video and TV: There are some TV streaming apps too, but I haven’t tried them much yet. And as I mentioned in the other article, the only time I tried playing a DivX video so far it did not work, so I still have to test that properly…

For Youtube, there this new app called cuteTube that I just tried for the first time. It’s definitely cute, built with the newer Qt tools.

CNN: This is an app developed by Nokia and CNN together. You can read news, watch videos, and there is citizen-reporter thing too. It’s great. I don’t use a lot, but I have been reading news there sometimes. Better than anything via the browser, that’s for sure. Webpages are certainly good, but it’s not the best. Native apps will never be replaces by a good browser with a good connection… Never.

Calculators: The calculator app that comes with Symbian is pretty basic, will only solve your basic needs. for more complicated stuff, I got this cvCalc_1 app, taht is ugly but at least can tell me the cosine of something. I haven’t tried or got the will to try any of the other paid calculator apps. I was a bit disappointed with the situation, so I am planning to make my own when I have the time. A reverse-polish notation calculator, of course.

DigitalClock: DigitalClock is a cute and useful countdown timer, chronometer and clock application, that emulates “old-fashioned” LCD watches. I got the paid version, because I wanted to reward the developers for the work in picking all the colors and creating the different display styles! 🙂 It only misses a “lap” button in the chronometer, and date display to be a complete pocket digital clock emulator.

SPB Weather: Definitely worth getting. The freely available Accuweather is no good, or at least that was my experience. SPB Weather’s widget is perfect to me. And so far the predictions have been reasonable. I think they read it from airport meteorological stations. I heard there is another app that is good too, and may be cheaper, have a look if you are interested.

Spotify: I started using Spotify right after I got my N8, and I was very happy with it. A must-have to any music lover. Spotify is available for Symbian probably because it’s an European service. I hope they keep supporting it through this wave of uncertainty surrounding Symbian. I unfortunately had to cancel my subscription, but one day I know I will be back.

Swype: I was skeptical about it at first, but now I am a convert. It improves on the Symbian keyboard in many things other than the swiping thing itself. To me the number one enhancement is the language selection, it only requires you to long-press the Q to bring a language menu. It would be great if it could be better integrated with the whole system, with split screen editing.

Adobe Acrobat Reader: It’s “freely” available. The quotes are because I’m pretty sure the price is actually included in what you pay for the device. On S60 phones it wasn’t free. I was happy because I got used to the reader available in the N800. My girlfriend had a 5800, and was angry that she had to pay for the PDF reader, so I guess this was a nice move from Nokia, I’m sure there were many other users out there who felt this should be included out of the box. It suffices for my PDF needs, but it seems there are better readers available if you need.

F-Secure: The app from the Finnish security company does a number of things, but I only use the secondary lock. I also “use” its ability of locking your phone if you text to it a command with a password. It also replies you with the position of the phone read from the GPS. I hope I never have to really use this!

Conclusion: I’m pretty happy with my N8. Many things could improve, I’m sure. I am also pretty sure I would not be happier with any other smartphone out there. I could _maybe_ become an Android user if I had to. And N9, of course, what I really wanted was an N9… But while I don’t get the money for it, or for Nokia’s next Linux phone that I am sure will exist, I’m looking forward to the Belle update for N8.

I think that’s enough for now. I want to thank very much the good folks from All About Symbian for the many hints I learned there.

And thanks for visiting my blog, I hope this review has helped you anyhow.

How to mix two lists with different lengths

Here is one interesting problem I was facing today. We have to lists, each may have a different size, and we want to mix their elements together forming a single list. We also want to keep the relative order of the elements, but more than that, we want the position from each element in the larger list to roughly correspond to that element’s original relative position in their original, smaller list.

If the elements have the same length, it’s pretty easy. We just pick one element from one list, then one element from the other. But suppose one of the lists have approximately 3 time as many elements than the shorter one. In that case you need to pick roughly 3 elements from the larger list, then one from the smaller, then three, then one…

Continue reading