Raspberry Pi 2 and Fletch


So I received my Raspberry Pi (2) on Friday evening. I spent the evenings this weekend playing with it. The Raspberry Pi’s are nothing new, and I’m admittedly late to the game here. While I’ve been interested, I didn’t have the money or time to invest into one before. There just wasn’t a factor to say “Hey look at me!” for it. However with my new position with DG Logik, working with IoT, it becomes more interesting subject for me to look into. And recently, the Dart team at Google started a side project called Fletch, which is designed not just to run on this, but eventually on a plethora of embedded, IoT devices. I missed my chance to be part of the first users of the Raspberry Pi and making “oh cool look!” projects. And honestly, it probably wouldn’t have been the right time for me to do so, as my limited knowledge with electronics would have kept me to more the OS level anyways.

But now with Fletch, I get to be one of the first users of Dart in this capacity on the Raspberry Pi. It is true, you can compile the Dart VM, SDK to ARM7 and run the full VM on the OS anyways. And I will do so too no doubt. But Fletch starts with the idea of getting right to the hardware level. It currently comes with packages all set for accessing the GPIO pins on the board, plus some gentle changes to how the VM runs.

The biggest change they made changes the VM to be two different parts. The first is a compiler. Dart compiles to bytecode. This bytecode is then sent over the wire to a smaller VM running on your Pi which executes it and returns any output back over the wire. Additionally, they made the decision to allow Dart to be blocking, but at the same time does not hog the CPU. If the VM is blocking on some operation, it can actually hand control back to the CPU until its done. This will be much more important when it comes to running on smaller devices in the future and makes for simpler programming for those devices, more akin to how they may be written now in Python (for the Pi) or C.

But please don’t take my word for it, as I’m sure I’ll mess up some of the finer details. Please check out the Fletch Homepage and get the details directly (who am I fooling, if you’re reading my blog, you’ve already checked out the page long before now).

The Fletch page has some nice samples to check out as well. I recommend doing the first couple verbatim, especially if you’ve not used electronics a lot yourself in the past. However after that I recommend that you actually start writing your own source copying the existing source and making alterations where you need to, this will generally be things like specifying different GPIO pins to work easier with what you have hardwired. I actually ran into issues with the second project due to a hardware issue which is known to happen. Basically there was feedback too close to the GPIO pin I was using, and it caused the pin to be in a state called “floating”. Where the input thought there was input based on background nose, and not actual value flowing into the pin (in fact it was totally disconnected from any wiring at all and still showed the same).

There are ways to resolve a floating value with both hardware, and internally. It’s called a pull up resistor, or a pull down resistor. One configuration will set the default value to ‘on’ and the other will set it to ‘off’. Because they’re so frequently used, particularly when using switches/buttons, each GPIO on the Raspberry Pi has it built in. In the Python libraries that comes with the Pi, it’s possible to set this value when setting up the GPIO pin for use. However, currently this same functionality is missing from the Fletch packages. I’ve filed a bug. Fortunately I was able to overcome that issue by using a different GPIO pin in the end, as well as using a GPIO Extension Board. (Not all extension boards are created equally. I have two, one from Sunfounder and one from Vilros, and the Vilros one I have is a much nicer extension board in layout.

That’s, however, not the only issue I’ve run into with Fletch at this point. The other main one, would be documentation. The API is fairly similar to Dart in most cases. However, particularly with the built in packages, there is no API documentation. The few times I’ve wanted to look up a method/function, it involved manually digging through the repository and trying to find the right package a method came from and hope there are doc comments there. For instance, what does SysfsGPIO.waitFor actually take for arguments (what’s the true and -1 from the samples?). Oh.

There’s a lot more I’d like to broach on the Raspberry Pi, and my experiences. But it’s getting late and I have a busy day tomorrow. More on it soon. It’s fun!

Posted in Dart | Tagged , | Leave a comment

Should I use Dart?


(This post started as a response to a question in the Dartisans Community on Google+ however, since I’m so long winded I decided to make it a separate blog post. This post is aimed at non-developer perspective. Someone with minimal programming experience in the past.)

So, should you learn Dart? To be honest, it depends on what you want to do.

I love dart, it’s a very capable language on the client and the server. It can be used for everything from creating webpages and web-based games (with pure DOM or WebGL/Canvas). It can also be used to create text based games on the CLI (command line interface). I’ve also used it in the past to write a MUD (basically a multi-player text game that you telnet into). I’ve used it for scripting, polling, and managing remote equipment and storing the responses in a database which can be polled, evaluated and generate pretty graphs with.

But Dart is not a ‘cure all’ either. For instance, you can’t write an operating system with it. You can’t get the same performance as you can with C for writing computer games (non-web based). It’s not as finely tuned for processing large amounts of scientific data as other languages. Dart is but one tool in the toolshed. Just like a hammer is little use for scraping paint off a wall.

I’m assuming, since in the original post you were looking at Dart and MeteorJS (though it could be any other framework out there as well), that you’re more interested in web-based stuff. Which is great, the web is such a capable place now and getting better every day. Before diving into a big framework like Meteor, it’s good to get an understanding of the language you may or may not want to work with (this was a big problem for many people years ago who jumped on the Ruby on Rails bandwagon without ever properly learning Ruby first). So now you’re looking at JavaScript and Dart.

Javascript can do all the things I mentioned above that you can do with Dart. You can create a MUD, or games etc. It also has the benefit of many many libraries to start with. Though as I mentioned, personally I suggest avoiding them initially as they can lead to poor programming. I know many developers who learned Javascript by way of the jQuery library and it took me a long time to ‘fix’ the code they wrote. Because they didn’t know Javascript, they knew ‘jQuery’, it lead to some really bad practices that killed their website performance.

Using just the standard Dart libraries, Dart has an advantage over what Javascript has “out of the box”. Many of the APIs already account for differences in browsers, where in Javascript that’s a manual process. (Fortunately that’s less of a problem now than it was 4 years ago when Dart was released for preview). Dart standard libraries provide a lot of functionality that is not readily available in Javascript. Some of that functionality you would need to either write yourself, or use a library for in Javascript, which I’ve already suggested avoiding. Here’s another issue with using too many Javascript libraries (especially getting started): they don’t all work together. Sometimes not at all. They use variable names which directly conflict with others or they literally change the Javascript language to suit their needs which in turn can impact the expected behaviour from another library.

Dart packages (libraries), mitigate that significantly. They can have incompatibilities, most often because they themselves may be using incompatible versions of a library. But generally speaking the likelihood of having a conflict between packages is significantly lower. Regrettably however, the number of available packages is also drastically lower than what you have with Javascript. So at the point you do want to start incorporating outside libraries, your options are much more limited. (Side note: This can be a good thing though, as it means less packages you have to evaluate to see if they will provide the functionality that’s right for your project).

The final factor to take into account when trying to decide if you choose Dart or not, is the information that’s available. Javascript has been around for a long long time. It will continue to be around for a long long time. There are tutorials and examples and groups and communities all over the place. There are groups and communities for specific styles of using Javascript, for specific uses of Javascript, for libraries, for just about any aspect of Javascript there is a community. Dart on the other hand is much smaller community. It’s also a community of individuals who, for the most part, came from other languages. They had a base level of knowledge before entering into Dart. Perhaps from a Javascript background, or Java or C#. Some use Dart professionally, some as a hobby, but the vast majority did not use Dart as a first language. As a result, it can be difficult for some of the community to recall the initial struggles you might have learning the language, as it was a struggle they.. skipped over.

Because the Dart community is more experienced, and also a smaller community than Javascript, it has less articles for learning the language, particularly from a non-developer point of view. There are books and articles out there, but they are much more limited in quantity than what is available for Javascript. They balance this however, by having a very devoted community who looks to constantly endorse the language. To share it and encourage others. It makes for a much more open, welcoming community than others I’ve seen.

On a final note, when it comes to differences between JavaScript and Dart, many of the experienced developers I spoke of previously choose Dart because the language (and standard libraries) do relieve many pain points they have experienced with other languages. Be it Javascript’s inheritance mechanism, or scoping differences. Be it a quicker development cycle with Dart and its tools over the Code-Compile-Test cycle from languages like C# or Java. Experience programmers look at Dart and choose Dart because of the benefits the language provides them. It’s my personal preference in a programming language.

Whatever choice you do make however, don’t believe for a minute it is the final choice. As a budding developer, your job is to always continue learning. Continuing growing your tool box of resources. You may gain an affinity for your first language, but it will unlikely be your only language.

[P.S. For the record. I’m extremely biased towards Dart. I can honestly say that my life is different because of Dart. That because I was an early adopter of the language, and have been part of the community for as long as I have, I have had opportunities that I may not have ever had otherwise. I’ve contributed early to the SDK, documentation. I have had to opportunity to interview with Google for a Dart related position years ago, and I currently work full time with the Dart language.]

Posted in Dart | Tagged | Leave a comment

Back to Dart

Just a quick update from mobile at the moment. I’m finally getting time to get back into Dart. A lot has changed since my last post.

After my last post about the Hackathon, I started a new job, moved to a Windows system full time for the first time in a decade, and a variety of other major personal life changes. It’s taken some major adjustments in my life, but I’m finally getting a wrangle on things and should have more time for development.

I have a large number of projects to first bring up to current releases of the Dart language and libraries. I’ll be holding back on any Polymer projects as that library has not completed its own upgrades to match Polymer 1.0.

Just last night, I managed to get my development environment set up. Since the Dart Editor is no longer supported, I’ll be using the Dart Sublime plugin for the time being. I also setup Chocolate on my Windows 8.1 machine to keep the SDK And Dartium up-to-date. Hopefully that will help keep my routine a little more similar to what I was used to on Ubuntu.

After the Windows 10 release I may consider a dual boot configuration, but at the moment my 2 1/2 year old is familiar with the Windows work flow. Additionally, I’ve heard issues with the touch screen input in Ubuntu that works well with Windows.

Posted in Dart | Tagged , , | Leave a comment

Marcato Hackathon


This past weekend, I had the opportunity to attend my first Hackathon (Aside: Apparently I was the first person to register for the even when it was posted back in July). It was hosted by Marcato Digital Solutions, with many great sponsors. The weekend involved lots of free energy drinks, beer, and great food. Of course there was also a lot of fun coding, and learning. Before reading my experiences, I recommend reading five things i learned from: a hackathon by Leah Noble (@leahcnoble) who was on the winning team (LOLCats). [Edit:] Also read a post from Caroline Louie (@caroline_louie): Marcato Hackathon. Good read from a developer who came with slightly less knowledge and made the experience a great opportunity to learn hands-on.

Continue reading

Posted in Personal | Tagged | Leave a comment

Dart, Docker, and Determination


Dart recently released official Docker Images for Dart. Docker is not something I’ve looked closely at in the past however I thought that this would make a good excuse to do so. If you’re not sure what Docker is, I’d recommend first checking out the official description.

Continue reading

Posted in Dart, Docker, mongo | Tagged , , , , | Leave a comment

Polymer Expressions – Filtering


Polymer is a great library. I use it every day and I’m often finding hidden gems that make life so much easier. Today I wanted to touch on some goodness of Polymer Expressions. In particular setting up and using filters.

Continue reading

Posted in Dart | Tagged , , | Leave a comment

Side Effects may include… being wrong!


Yesterday, I wrote a post about Side Effects. My post was based on observed behaviour, as opposed to the mechanics of the Dart VM. I am happy to report that my last post was wrong. Yes I was wrong, and yes I am extremely happy about it! I received a number of comments indicating that no, Dart is a pass-by-value for everything. Additionally I received a number of comments indicating that Dart is actually always a pass-by-reference. In fact, both are correct… sort of.

Continue reading

Posted in Dart | Tagged , | 1 Comment

Side Effects


Dart, like many other languages, uses pass-by-reference for complex objects, and pass-by-value for simple objects. This can occasionally be confusing or surprising to someone new to the language. It may not always be clear when your function will have side effects or not. So I decided to create a simple project which helps highlight when you can expect your function to have side effects.

This post uses terminology which is totally wrong. See my follow up post Side Effects may include… Being Wrong! The table here is still good, but has been slightly modified to accurately reflect the terminology and what is going on under-the-hood. Apart from that I’m leaving the remainder of the post as is, however please, please please read the follow up post.

Continue reading

Posted in Dart | Tagged , , | 1 Comment

Project Euler

Euler PortraitI’ve added a new site to my daily workflow. Project Euler. Each day I complete one or two problems first thing in the morning when I get to work to give my brain a kick start for the day. Naturally I use Dart as my language of choice for the problems.

For those of you unfamiliar with the site, basically there are (currently) 468 different programming challenges/problems. You can choose to complete them in any order. You can use any programming language of your choice to derive the solution. Once you’ve arrived at your solution, you simply submit the answer to find out if it is correct or not.

Continue reading

Posted in Dart | Tagged , | Leave a comment

Dart Front and Back

I’ve been asked to describe/talk about my current setup involving Dart at work. In order to properly do that, I need to provide a little background information as to where I work, what I do, and what I started with.

I work at an ISP. Our company is small enough that I can take certain liberties in how I accomplish my task or goal, and yet large enough that those tasks and goals are constantly shifting. Early on I started in the technical support department, and having some programming experience I was provided with the opportunity to help maintain some of our internal web applications.

Continue reading

Posted in Dart | Tagged , | Leave a comment