Orr Sella

  • Random
  • Archive
  • RSS
  • Ask me anything

Scala Development Using Sublime Text 2

I love Sublime Text. It’s a fantastic text editor. And, as I’ve written about before, I use it for all my development. As I put it back in October:

By far the best text editor for mac. I use it for all my coding. You obviously lose some functionality in comparison to full-fledged IDEs (like IntelliJ), but the core functionality + the wide range of plugins make up for it. Also, I just love how much more productive I am in this minimalistic and bare-bones environment.

I still stand by this description. For Scala development, I find that the combination of Sublime as the text editor and sbt as the build tool, is a winning combination.

As it turns out, I’m not alone in this thinking. Following the Coursera course on Functional Programming Principles in Scala, Heather Miller and Martin Odersky posted an article titled Impressions and Statistics. It’s a pretty interesting read, with many stats on the course itself and the participants (the raw data in available on GitHub if you’re interested). In the post-course survey, participants were asked “which editor do you normally use?”. A total of 6% responded Sublime, which amounts to 3000 people of the total 50,000 registered students. Also, about 35% said they don’t use one of the “proper” IDEs out there (mainly IntelliJ and Eclipse).

Which brings me to my main point. One of the things I miss the most when using Sublime and not IntelliJ (for instance) is the lack of integration with external dependencies. A lot of times I like to peek at the source code of the libraries I’m working with. Sometimes it’s to see how certain things were implemented, a lot of times it’s to see a class’ interface and available fields/functions. I can do all this on the library’s GitHub repo/website, but this is uncomfortable. It takes you out of the context you’re currently in.

Here’s how IntelliJ allows you to browse the source code of your external library dependencies:

image

and this is exactly what I want to be able to do in Sublime – have all the external sources available for me in the same project windows. So this is exactly what I did, and I packaged this functionality into a new sbt plugin: sbt-sublime.

The new plugin generates a Sublime project file for your sbt project, downloads all available dependencies’ sources, and adds them to the project in a very similar way to how IntelliJ does it:

image

As you can see, both screenshots are for Twitter’s bijection repo. The generated Sublime project adds the “External Libraries” folder with all the sources. The difference in the dependencies list between the two screenshots, is that IntelliJ, by default, displays all dependencies transitively, that is the entire dependency stack (including the dependencies of your own dependencies). sbt-sublime, on the other hand, displays by default only your immediate dependencies. This, and other parameters, can be easily configured.

So that’s it. If you’re using Sublime Text for Scala development, I encourage you to try out the plugin. Once you have it you just: 1) clone a repo 2) run “sbt gen-sublime”, and 3) you’re ready to go with a Sublime project with all dependencies.

If you’re using some other text editor for Scala development, It’s probably pretty easy to adapt this plugin to create other project types. All you need to do is create a new project, add the root directory and the external sources directory.

For more information and important notes please check out the project page on GitHub.

UPDATE: Sublime Text 3 Beta has just been announced. One of the great new features is Goto Definition, which allows you to navigate to the definition of any class/trait/interface/method/etc. I already tested it and it seems to work very good (the beta is available to current licensed users). This new feature only enhances the great need for sbt-sublime – you can now navigate to external sources that more easily, and only having the sources available in the Sublime project enables Sublime to index them.

    • #scala
    • #sublime-text
    • #sbt-sublime
    • #development
    • #github
    • #sbt
    • #open source
  • 3 months ago
  • 4
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Introducing sbt-stats: An SBT Plugin For Source Code Statistics

One of the first and most obvious selling-points of Scala to Java developers are its brevity and conciseness. A classic example, as found in Odersky’s Programming in Scala, 2nd Edition, is of a class with two public read-only properties. In Java this would look like:

https://gist.github.com/e145e41836a0e524ec8d

And the Scala version:

https://gist.github.com/483a885e8c64829ca88b

Even without counting blank and closing-brace lines, the Java version is 6 times longer. Obviously this is a very specific example of boilerplate code that Scala gives us for “free”, but the core concept of succinctness can be found throughout Scala. This is a principle I value very much, and I try very hard to have my own code concise yet readable (a tricky sweet spot).

So after I had completed my Scala library for Tumblr’s API – tumblr4s – I was curious how it stacked up, in terms of the amount of code needed to implement the entire functionality of the Tumblr API, against other Java implementations which have equivalent functionality.

Before starting to write a Scala library for the Tumblr API, I researched existing alternatives (the whole reason I wrote it was because I couldn’t find a Scala version). During my research I came across tumblr-java which is exactly as it sounds. So I wanted to compare the size of both projects’ source code.

I wanted to break my comparison down to a few parameters: number of files, lines and characters, and also calculate some averages. I also wanted some raw file-size numbers just for the sake of it.

Now I use Sublime Text 2 for all my development. As far as I know and could research, it doesn’t have any built-in functionality or plugin that enables me to get the stats I wanted. I could use some clever searching using regular expressions, but it wouldn’t provide exactly what I wanted. I also wanted to only analyze source code – Scala and Java files – without counting sbt build files, testing code, etc.

So my next move was to find an sbt plugin which does this. Surely there had to be a plugin that provided such functionality I thought. Such a plugin seemed like a perfect fit in my mind. And again I couldn’t find any, and that’s when I decided to write it myself: sbt-stats.

The sbt-stats plugin adds the “stats” task to sbt, and is meant to be run from the sbt console (it’s return type is Unit and it outputs the results using state.log). The task is scoped to either the Compile or Test configurations, so you can get statistics on your source or testing code, but it’s obviously most interesting for Compile. The idea is to get a high-level view of the project (see sample output below and on the project page).

In addition to providing some basic stats as default, I made it pretty easy to extend. Some uses for it could be more advanced analysis, such as counting the number of classes, traits, methods, etc. To do this all one needs to do is write a small Analyzer of his/her own in the basedir/project/ “project”, and add it to the build settings (see Extending). This way you can enjoy the functionality without implementing the sbt plumbing yourself. If you have an idea for a great Analyzer let me know, or better yet – add it yourself!

And now for the comparison of tumbl4s – how did it stack up against tumblr-java?

Here are the results of the stats plugin for tumblr4s:

https://gist.github.com/98b91afc0e51657b6c0a

And for tumblr-java:

https://gist.github.com/c32f4fc0f75c51294e90

We can see that tumblr4s has 928 code lines and 32,336 code characters, while tumblr-java has 580 code lines and 20,910 code characters. This amounts to about 55/60% more code in tumblr4s (depends if you count by chars/lines, respectively). Ha? What gives? I thought Scala was supposed to be more concise than Java… :/

Let’s try to break down the results (read: give excuses). Here are possible explanations for the difference:

  1. tumblr-java is about a year old. While it works with Tumblr’s v2 API like tumblr4s, it doesn’t implement all its functionality. A few missing methods I quickly found: getBlogLikes, getSubmissionPosts, getTaggedPosts. It also doesn’t provide all available parameters for blog posts querying methods (like getBlogPosts, getQueuedPosts, etc.). Now this isn’t necessarily the developer’s fault – Tumblr keeps adding functionality to their API, without changing its version. I’ve noticed this during my own development, when a new end-point suddenly appeared in the docs (such additions are usually announced on the Developer blog which I subscribe to and hope to keep tumblr4s up-to-date). So the missing features could explain a small difference in code amount, but surely not all 50%.
  2. Most of tumblr4s’ code resides in the “model” package (the main TumblrApi class, which implements most of the business logic, is 469 lines long, including a lot of comments). And most of the model is various types of Post classes (TextPost, ImagePost, etc. totalling 8 classes). Now, in-order for them to all be immutable (Functional Programming 101’s first lesson), they all redefine the common Post members (27 fields) in their constructors (I could not find a better solution for this, if you have an idea let me know!).
  3. I am not an experienced enough Scala developer, and so the code can be rewritten in much better and concise ways.
  4. The sbt-stats plugin is wrong.
  5. The notion that Scala is more succinct is wrong.
  6. Scala sucks (haters gonna hate).

I think the real reason is a mix of 1-3, and hopefully not 4 (perhaps I should add more unit tests? :). Obviously I don’t believe 5 and 6 are true, otherwise I wouldn’t be putting so much effort into Scala. But the real question should be – does this matter at all? Brevity and conciseness are important, but not more than clean, readable and testable code. I think I’ve achieved all those with tumblr4s, and so I’m proud of all 93,954 characters of it (including comments)!

Also, I’m happy I had the chance/reason to write sbt-stats. It’s been fun, but most importantly it forced me to really read sbt’s Getting Started guide once again (3rd time’s the charm) and some of the detailed topics, and now I can say I truly understand how it works, and appreciate the amazing work and effort that has been put into this project.

Also, as a side bonus, I learned about publishing to OSS Sonatype (as usual, here’s an excellent guide from Cake Solutions) and so sbt-stats and tumblr4s are now both available on the Maven Central Repository so they can be easily added to any project.

Check out sbt-stats and let me know if you have any feedback – I’d love to hear it.

    • #scala
    • #tumblr4s
    • #sbt-stats
    • #github
    • #sbt
    • #open source
  • 4 months ago
  • 1
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Maps have become a hygiene factor for a platform. Not having them makes a platform repulsive but having them offers no attraction.
Great analysis of the “maps business” by asymco’s Horace Dediu. Bottom line – nobody wants to be in this business.

Source: asymco.com

  • 5 months ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Love this geeky update description for RESTed.
If you’re not familiar with it, RESTed is a great little app for testing APIs – allows setting custom headers, parameters, encoding, etc. You can save a template of each request after customizing, making it really easy to continuously test endpoints you’re writing, or just for exploring a new API.
Thanks Hello, Resolven for a great app!
Pop-upView Separately

Love this geeky update description for RESTed.

If you’re not familiar with it, RESTed is a great little app for testing APIs – allows setting custom headers, parameters, encoding, etc. You can save a template of each request after customizing, making it really easy to continuously test endpoints you’re writing, or just for exploring a new API.

Thanks Hello, Resolven for a great app!

  • 5 months ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Instagram Blog: Instagram 3.2 - Improved Camera with a New Filter

instagram:

Today we’re excited to announce the release of the largest upgrade to our Instagram iOS camera since it was revamped just over one year ago. The camera has been the core part of the Instagram experience since the day we launched and as a result, we’ve made significant improvements to its look and…

Change I’m most excited about: “Filtered photos are now saved to a separate album called “Instagram” in the iOS camera roll.” – Awesome

  • 5 months ago > instagram
  • 1038
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Introducing tumblr4s: A Scala Library For The Tumblr API

Back in February of this year I stumbled upon an amazing article on HighScalability.com about Tumblr’s infrastructure. It’s a great read for many reasons (go read it). One of the greatest take-aways I had from this article, was this “new” programming language called Scala. I had never heard of Scala before, and was immediately intrigued. Also, after doing a lot of PHP back at the time – which I hate – I wanted something new, fresh and fun.

I started reading “Programming in Scala 2nd Ed” by Martin Odersky – creator of Scala – and was completely blown away by the language’s beauty, design and powers. I became obsessed with it, reading dozens of articles and tutorials, going thru many open source projects and watching conference talks. I even started listening to The Scala Types podcast. To top it off I attended the Coursera course given by Odersky himself called “Functional Programming Principles in Scala” (which attracted over 50,000 developers).

Every coder knows that the best way to really learn a new programming language is to dive right in – start writing code and doing your first project. Seeing as I had Tumblr to thank for introducing me to Scala, I figured it was only appropriate I do something with it’s API for my first project. Unfortunately I couldn’t find any Scala library for the Tumblr API, so I figured I’d write it myself.

And so tumblr4s is my first Scala project. It’s supposed to be a simple, elegant and idiomatic Scala implementation for Tumblr’s API. The GitHub repository has some examples on how to start using it. It’s pretty straight forward, and implements all the functionality of the Tumblr API.

I have put a lot of effort in to this, attempting to make it as “Scalaty” as possible. It took me a while to change my way of thinking from imperative/mutable to functional/immutable. In my code I tried to follow these concepts meticulously:

  • Functional programming – everything is an expression, no side-effects
  • Immutability – no use of vars and only immutable collections
  • Conciseness
  • Use the appropriate Scala tool in the appropriate place
  • Not write Java code in Scala
I also tried to comply with the Scala Style Guide as much as possible, mixed with some Effective Scala advice from Twitter.

And so I must say I’m pretty happy with the result. If you get a chance, please check the library out and let me know what you think. I’m especially interested in hearing the opinion of experienced Scala developers on some of the things I did, and if I should have done some things differently. I’d love your feedback.
    • #scala
    • #tumblr
    • #api
    • #github
    • #tumblr4s
    • #open source
  • 5 months ago
  • 17
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

My Top 10 Mac Apps

A month and a half after getting my first Mac – the MacBook Pro with Retina display – here’s my list of best and most used Mac apps:

  • Chrome – After trying to use Safari for some time, I reverted back to good ol’ Chrome. I like using the Beta channel – for me it’s the perfect sweet spot between stability and new features. One I really wanted and just got: Retina-compatible favicons for tabs and bookmarks bar items.
  • Sublime Text 2 – By far the best text editor for mac. I use it for all my coding. You obviously lose some functionality in comparison to full-fledged IDEs (like IntelliJ), but the core functionality + the wide range of plugins make up for it. Also, I just love how much more productive I am in this minimalistic and bare-bones environment.
  • 1Password – I don’t know how I lived without it. My use of KeePass on Windows seems like a nightmare in retrospect.
  • Soulver – Hands-down the most brilliant app I use. This is such a great tool, which saves me SO MUCH time. Heard about it on Build & Analyze. As Marco Arment put it: if you open Calculator more than once a day then this app is for you.
  • Transmit – Beautiful FTP/SFTP/S3 client.
  • Pixelmator – THE image editor for developers who don’t know/like Photoshop (or don’t want to pay for it).
  • Reeder – Finally RSS doesn’t feel like work, but actually fun. I can never go back to Google Reader. The only thing missing is Notification Center support. Hope that’s coming.
  • Carousel – The best Mac Instagram client.
  • Tweetbot – The beta is over, final version has been submitted for review. Review times for the Mac App Store are *crazy* these days (26-days crazy), but once it’s approved it’s going to make Twitter a lot more fun for me.
  • Parallels – For when you really have to open that word document, especially if dealing with RTL languages.

As I tweeted earlier, it’s baffling and fascinates me how switching to Mac has made me want to pay for the software I use. I never remember having this feeling as a Windows user. The fact that I payed for these apps makes me enjoy them a lot more. I feel great satisfaction by owning these great apps. I guess this is the geeky-developer equivalent of a woman’s feel-good shopping spree at the mall, as a means of comforting :).

  • 7 months ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
The Internet Map (via @liorwn)
Pop-upView Separately

The Internet Map (via @liorwn)

  • 9 months ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Apple’s Reality-Check Quarter In Charts by Dan Frommer. Best summary of Apple’s 3rd quarter results.
Pop-upView Separately

Apple’s Reality-Check Quarter In Charts by Dan Frommer. Best summary of Apple’s 3rd quarter results.

  • 10 months ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Highlight – the app that will make your eyes bleed (for the life of me I can’t stare at that logo for more than a second). They just released a new version, but who has the guts to go thru their app page and catch a glance of that mind-fuck-of-a logo?
Pop-upView Separately

Highlight – the app that will make your eyes bleed (for the life of me I can’t stare at that logo for more than a second). They just released a new version, but who has the guts to go thru their app page and catch a glance of that mind-fuck-of-a logo?

  • 10 months ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Page 1 of 5
← Newer • Older →

About

Tech, code and other musings by Orr Sella. I do frontend and backend at Zemingo and write Scala on my free time. Yes, it's sad – drop it.

Me, Elsewhere

  • @orrsella on Twitter
  • Facebook Profile
  • orrsella on Foursquare
  • Google
  • Linkedin Profile
  • orrsella on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile
Effector Theme by Pixel Union