Sunday, July 8, 2012

Dumping PHP For Go

Background

It has been a long time coming for me to switch out of PHP for my main programming language.  I have been working with PHP for years and have grown tired of the limitations/issues.  It has been hard for me to convert, being that there are always jobs for PHP programmers out there and I gotta eat! For me, the aggravation coming with working with PHP has forced me to switch.


Why do you hate PHP?

I don't hate PHP at all.  The language itself has many advantages like a great community, numerous libraries (although how many different MVC frameworks can you have?), great documentation, and ease of entry.  There are libraries to connect PHP to virtually every database, REST API, or other third party software.  These are all reasons I began using the language in the first place.

PHP is supported on virtually every web hosting company on the planet, making PHP a useful skill to have.  There are some great open source frameworks and apps like WordPress, Zend, Joomla and too many others to list.

Why no more PHP?  First, I should probably clarify that I will continue to use PHP as many of the projects I'm working on still use PHP.  However, there are many quirks about PHP that have been bothering me.  I won't go into detail because I will not be saying anything new about the subject. If you want to read the most epic of rants on PHP issues, see this post.



PHP code, especially large code repositories, have become difficult for me to enjoy maintaining.  Sometimes your app just stops working because of some typo in your code or the spaghetti code becomes just too unreadable.

PHP just doesn't seem exciting for me anymore.  There doesn't seem to be anything exciting happening.  Yes PHP 5.4 was recently released which has the new Traits feature, but other than that, not much has been happening with the language and nothing interesting as far as apps or frameworks. The only object that piqued my interest was Laravel.

Why not Python/Ruby/Java/Any Other Language?

I like to consider myself open to trying new programming languages.  Even if you don't wind up using a language long term, sometimes your programming skills can still benefit from solving solutions from a different point of view.  Below is a quick overview of my dealings with other languages.  Most were brief enough that they shouldn't be taken too seriously.

Python - I have no problems with Python.  I have completed a couple of projects in Python and find it a joy to work with.
Ruby - My only experience was with Ruby On Rails around version 0.9.3.  At the time, the framework made coding easier but at the expense of performance.  Scaling was terrible at the time.
Node- This seems to be all the rage.  Everybody likes to use the term "Non-Blocking" to make themselves seem cool.  The draw is to be able to code the same language client side and server side and even share that code so you don't have to write validations in two places.  Node is still young but provides ample libraries with a large developer community already.
Java - Too bloated for me and if I use it there is a possibility Oracle might sue me!
C -   I mostly used it in school and haven't had the need to use it since.
C# -  This language seemed well thought out, but I am not into using .NET products and Mono just wasn't a viable solution for me.

There are some languages that I would like to still try (for various different reasons) like Clojure, Scala, Dart, Smalltalk, Erlang, and Haskell.  I will get to them when I can.


Why is Go the Shiznit?

Go makes me a better coder!  I enjoy coding more with Go and was productive very quickly.  The documentation was complete and organized.  The support forums are great and are frequented by the core contributors of the language.  Effective Go is a great way to get started with Go.

I like the multiple return values instead of exceptions which forces you to deal with errors right away.

Some people don't like static typing and strict compilers, I do.  It saves me a lot of debugging time and prevents my program from crashing in a rare use case.  The compiler will tell me if I declared a variable and didn't use it or tried to use an undeclared variable, both signs that I have probably made a typo somewhere. The compiler is very fast!  Large apps can still compile in under half a second.

Since I'm not a sysadmin, I prefer to pay extra to have my code managed by someone.   Besides Google App Engine, people have implemented Go on Heroku and OpenShift.

Although I haven't used it, Go's concurrency model seems straightforward and easy to use.

Interfaces and reflection are awesome.  Takes a little getting used to, but once interfaces click in your head, you'll be hooked.  There is a blog post that sums interfaces/reflection up better than I can at http://blog.golang.org/2011/09/laws-of-reflection.html.


Conclusion

Go helps me write cleaner and more maintainable code.  Now that Go 1 has been released, the code base has really stabilized, allowing me to feel more confident about using Go in a production environment.  The maintainers of Go say: "People who write Go 1 programs can be confident that those programs will continue to compile and run without change, in many environments, on a time scale of years."

Since there are millions of PHP users and six people who read this blog (Hi Mom!), I doubt that I will cause of a shift of PHP users to use Go, but maybe the next time you have a project that is a fit for Go, you will give it a try!  You can create Google App Engine projects for free to help you get started.






18 comments:

  1. This matches many of my own feelings.

    ReplyDelete
  2. You should post a simple hello world with Go on Heroku.

    ReplyDelete
  3. I have never been a PHP developer but I do Python. I agree with your last header completely, glad I'm not the only one who feels that way.

    ReplyDelete
  4. I'm a PHP developer, but I'm trying to switch too.
    But I'm interested in HTML5 so I'll go for DART

    ReplyDelete
    Replies
    1. Go is great to use the features of HTML5. My web applications use the native facilities to handle for example json and websockets in an incredibly easy way.

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. If you like python/ruby please check groovy/grails.

    ReplyDelete
  7. I read this article for the fourth time
    I think I also want to move from the php language to a new language and more efficient
    In this article based on comments
    Dart better for me to online applications because it is server & client side will save time
    But I want to Go with the language of another client side

    ReplyDelete
    Replies
    1. Glad you took the time to read it once let alone 4 times!

      Delete
  8. As you immerse yourself with Go. You will find that some of it's virtues besides speed and concurrency are the tool sets. Go's philosophy is aimed at optimizing the efficiency of the end user. There are so many small optimizations to mention; such as "go fmt" which automatically formats indentation of your builds, "go doc" built in documentation, etc,...

    Another major encounter was design. Note, that I come from an Object Oriented language (Ruby). If this is your case; you will find that the idiomatic way to Go programming is a bit different. Go is a procedural language, but it's implementation details are slightly different than one might imagine, almost anything you can achieve using inheritance in another language, you can build in Go! using what gopher's like to call as, "composition."

    There is an awesome article written by Nathan Youngman which I highly recommend every beginner should read. It really put many details into perspective for me. Go Object Oriented Design

    ReplyDelete
  9. I wrote a similar article a few years ago. For me it was PHP to possibly Groovy and Grails. I found that too bloated right along with Java. I also went through Go when it was too young and Python which I loved. I'm now on Go as my language of choice. Easy to write, compiled native code, and probably the least problems I've had with typed languages. Just can't beat it.

    ReplyDelete
  10. The draw is to be able to code the same language client side and server side and even share that code so you don't have to write validations in two places.

    pgp download

    ReplyDelete
  11. What Database do you suggest to use with GO? is MySQL good to go with Go?

    ReplyDelete
    Replies
    1. There are libraries for all the major databases out there to use with Go. I would recommend using whichever you are most comfortable with. If you like MongoDB, there is a great wrapper for it.

      http://labix.org/mgo

      Delete
  12. Go is extraordinary to utilize the characteristics of Html5. My web requisitions utilize the local offices to handle for instance json and websockets in a fantastically simple way.

    cool website design // Best Web Design

    ReplyDelete