The obligatory, “I love golang” post

Golang gopherI’ve spent the last year and a half designing and building a microservices architecture in Go (First rule of Go. Always google “golang”.) After all this experience with Go, it’s finally time to write the obligatory “Here’s why I like Go” blog post. This post, of course, is a required assignment for all real gophers (that’s how golang users are referred to. Cute, ain’t it.) All kidding aside, I’ve really fallen in love with Go. Most of my work is done in Go these days, and it’s a really powerful language, with some good design choices. However, it’s not a panacea. It won’t solve all your problems by itself, and there are some times and places, where it really doesn’t fit.

First of all, for those who have been living under a rock for the past couple of years, and may not have heard of Go, here’s a quick run down. Go, or golang, was invented at Google to solve some problems that they were having with other languages. It’s a systems language (think C) based on C, but with specific design choices intended to make it simpler, and more flexible than C. Wikipedia says that it is “a compiled, statically typed language in the tradition of C and C++, with garbage collection, various safety features and CSP-style concurrent programming features added”. First of all, it’s garbage collected, so no more `malloc` baloney, and shooting yourself in the foot because you forgot to deallocate memory. Second, it’s got a crazy awesome concurrency model built in! This is the thing that gets most people excited about Go. Go makes it dead simple to write highly concurrent software. That’s a post all to itself, so I won’t get into details here, but seriously, it’s damn good. At heart, it’s still just managing threads on the OS, but Go abstracts away the dirty work of creating and managing those threads. Third, it’s a compiled language, which means that deployments become so much simpler, there’s no “dependency hell”, since you can compile a statically linked binary executable. It’s completely self-contained, and you just drop that binary on the machine that you’re deploying to. If you’re my age or older, you might think that’s ironic, since one of the “benefits” of scripting languages (like perl, php, ruby, etc…) was that there’s no need to compile them. It’s funny to me that we seem to have come full-circle there.

With all this Go goodness, are there any downsides? Well, kind of… Go is still a fairly new language, and the ecosystem isn’t as strong as some others. Perl and Python have been around long enough that no matter what problem you’re trying to solve, there’s probably a well vetted library that will help. That’s not necessarily the case with Golang. Of course, that’s changing as we speak. As more and more people start to use Go, more and more libraries get created, and the ecosystem just keeps growing. Golang is designed as a systems language, meaning it provides low level hardware access, so you’re not going to want to write a web CMS with it. With that being said, people certainly can and have written web CMS’s with Go. Personally, I don’t think that type of high level application is the sweet spot for Go. However, I do think that, for example, building a REST API for that web CMS, is a perfect application for Go. And as a matter of fact, that’s exactly what I’ve been doing lately, building REST API’s in Go that provide access to other services and systems.

In any case, Go just works for me. I’m planning a series of posts, where I’m going to go into more depth regarding some of Go’s features that I’ve either very fond of, or that I find myself using all the time. But for now, I just wanted to get back into the swing of writing. I just realized that I haven’t posted anything at all in 2015.

Development environments done right, with Vagrant, Puppet and VirtualBox

vagrant_structure

When I first started out in web development, I worked directly on the server. I had an FTP client and I’d download files, edit them, and re-upload them. If it was a “serious” project, I might even use source control. I thought this was a pretty handy way to work… Looking back on that workflow, I’m embarrassed, but the thing is, I know people who still work that way. I’m not going to go into the merits of having a dedicated development environment, automated builds and tests, etc… Just take it as a given that you need them. With that being said, however, it’s always a pain trying to set up a new development environment, and having an environment already set up on my laptop doesn’t guarantee that it’ll be the same environment that the next client has in production. If you’re on a different machine, it’s a problem. I’m going to talk about how I’ve solved this age old problem using Vagrant, Puppet and VirtualBox.

Continue Reading…

Moving Kohana to a non public directory

Kohana, PHP framework

This is the second post in my series on the Kohana php framework.  For more, see:

Part 1: Getting started with the Kohana php framework

One of the simplest, and most basic security precautions that you can take is to move your application’s files into a non-public area of your webhost. Having your applications code and configs sitting there in your document root is just never a good idea. An attacker could very easily gain access to the source code of your application, as well as configuration. Next thing you know, there’s empty beer cans all over your apartment and the silverware’s missing. In general, this applies to any kind of web based application, but I’m going to be dealing specifically with Kohana, as part of my series on Getting Started with Kohana.

Continue Reading…

Perl arrays for fun and profit

In my day job, I deal with a lot of perl. After really taking the time to learn it, and working with it in a production environment, I really have a new respect for perl. But that’s a topic for another day. The other day, someone presented me with a perl coding challenge, and it took me a while to come up with the answer. Granted, I’m not really a perl guru, so I’m not too concerned, but I wanted to talk about and document how I solved the problem. The challenge can be simplified a little bit, and restated almost like a homework problem:

Given 2 arrays, find the union, intersection and difference.

See, here’s the thing. Most every other high level language makes this pretty trivial. PHP has the built in functions array_intersec and array_diff, in Ruby, you can just do something like ary1 & ary2 or ary1 - ary2, etc… Perl’s arrays suck eggs. I’m serious, arrays in perl are virtually useless… Well, that’s too strong. Array’s in perl are emenintly useful, they’re just kind of dumb. In order to do most serious processing in perl, you wind up turning things into hashes. And that’s basically what you have to do to get the array intersection, difference and union. Here’s a little script that does the job.

Continue Reading…

Custom macros to integrate Todo.txt with Komodo Edit

Komodo edit code editor

I went to a PHP developer’s meetup recently, where the topic was IDE’s. As some of you may know, I’m a dedicated Vim user, but that’s because I’m most productive using Vim. I don’t have any extreme aversion to using an IDE. As a matter of fact, if I ever find one that really works for me, then I’d start using it. In any case, I’ve started trying to work Komodo Edit into my workflow. As far as I’m concerned, Komodo Edit is the most flexible IDE out there, and that’s part of the reason that I have trouble finding IDE’s. At any given moment, I may have a mix of perl, python, ruby, xml, yaml, javascript and html files open. No IDE that I’ve ever used has been able to handle that kind of mix. Language optimized IDE’s like PHPStorm or PyCharm are great for their intended language, and if all you do all day is work PHP, then that may work for you. For me, Komodo does a good job with almost every language that I work with.

Continue Reading…

More Cascading AJAX Dropdowns with CodeIgniter

ci_logo

Probably the most popular post in the history of this blog is “Populate DropDowns with jQuery and Codeigniter”. In that post, I gave a quick overview of how to set up a dropdown or select box that depends on the value selected in another form element. That post was never really intended to be a complete “How To”, but it’s been such a popular post that I wanted to revisit the idea, and write up a more complete discussion of this technique.

What I’m going to do here is to create and populate an HTML select element using values that are dependent on a selection in another HTML input. In this case, I’m using two select elements, but you could adapt the technique for any kind of input. For example, let’s say you have a form that displays data for a zip code. Now, there are a LOT of zip codes in the US, and you probably don’t want to make your users scroll through such a long list to choose the value they’re interested in. So, you add another HTML select element that allows the user to choose the specific state that contains the zip code. So, initially, the zip code select element is blank, or set to some default value. Then once the user chooses a state, the zip code element is populated with all of the zip codes for that state. Nice, huh?

Continue Reading…