A few years ago, I published an Android game, mostly as a hobby. I actually fell into making the game, it was originally planned to be a demo for a talk I was considering giving at a conference. The plans few through, but I kept on tinkering with the game. It was also a good source of material for earlier posts on this blog.
The result was Sedition for Android.
About a about ago, I got the crazy idea to port the game to run inside a browser. I have done some work with the Google Web Toolkit in the past, and I've been very impressed with the way in which it can make developing a rich client side application feel like you're developing a traditional desktop application. GWT compiles Java language code into very efficient complied Javascript. With the advent of HTML 5's media support and WebGl, I had everything I needed to take the Android source and port it.
Originally, I called it "Sedition 4 Chrome", since I was planning to make it a Chrome packaged app and put it in the Chrome app market. I may still do that. Writing a Chrome app gives you access to more features that you can do with lowest common denominator general web apps.
It has numerous quirks, and the rendering especially is not quite right in several ways, but that actually matches the last released version of the Android version. I do plan to fix both eventually. Some of the rendering oddities, especially "sprite parallax" are much more noticeable on large screens than the small mobile screens the game used to run on.
I also have a few ideas for the general engine I developed while working on that game that might come in handy for some of my other projects.
It's a fun project to work on, and in part I wanted it to server a sort of a portfolio of what types of applications I can develop.
Play it yourself at
http://anibit.com/sedition/
--P
Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts
Monday, February 22, 2016
Wednesday, March 11, 2015
A ramble on web development from a non-millennial developer's perspective.
Having a background in desktop and embedded software development, web application development technologies frequently stymie me. I get "the good parts" of Javascript, but I often feel like Javascript makes what I've come to consider good practice in application architecture difficult. The loose typing of Javascript is an appeal to so many, but it can make it hard to maintain a very large code base.
Consider:
Javascript:
var foo = function (payload) {
var timestamp = payload.getTimestamp();
//some code that does something with timestamp, etc...
}
There is an inherent code interface requirement for anything passed into the function foo that it must have a member function named getTimestamp, and that function must return a type suitable for the expected operations.
There are essentially 4 ways in Javascript that a developer who wished to use function foo can discover this implicit requirement:
- Inspect the internals of the function foo, to learn all of it's expectations of the passed in type
- Read documentation bequeathed by the author(s) of foo
- run a "lint" -type tool for static analysis to catch improper usage.
- run the code and debug the exception that gets thrown when you pass it an invalid object.
All of these options, except maybe the lint option require manual human action. All of the options, including the lint option, are quite fallible. I did not include a 5th option that is unit testing, unit testing is a good thing, but it does not even begin to help this particular problem. For starters, the unit test will not replicate the real world usage. Where was the payload object created? It might come from a call back from within a callback from within a callback using an object stored form some earlier callback. Similarly, lint tools are a good thing, but they are far from perfect as well, and more cumbersome to use than a compiler.
compare the Javascript with the equivalent C#
interface IPayload
{
DateTime getTimestamp();
}
void Foo(IPayload payload)
{
var timestamp = payload.getTimestamp();
//do some stuff with timestamp
}
Now this example is trite, but the point is that as the size of your application grows, and you pull in more and more 3rd party code, the occurrence of problems surrounding the "hidden contracts" in dynamic languages like Javascript grow. In the C# version (or just about any statically typed, compiled language), you know immediately, and so does the compiler, what is expected of the payload object passed to Foo, it's contract is clear, and rigid.
There is a lot of thing appealing about how Javascript works and dynamic languages. Due to the nature of web the web, deployment has always been more of a challenge than with desktop applications. The ability to swap out a single file has it's appeal. Java server side tried to alleviate this with the servlet system and WAR files. It's also more terse, and superficially more forgiving. (Any object could be a "payload" in the Javascript version so long as it has access to the getTimestamp prototype.
Also, there is this appeal in the perception that a change in a third party dependency won't break your application. I think the problem is with dynamic scripting languages is that your relationship to your dependencies becomes a "gentleman's agreement", and not an enforceable contract. Say in the next version of the foo library, the authors made to following changes to foo:
var foo = function (payload) {
var timestamp = payload.getTimestamp();
payload.resetTimeStamp();
//some code that does something with timestamp, etc...
}
Maybe this was documented, no big deal right? If your code was such that you could find everywhere that payloads were created, great. But what if it's not that easy? Again, this is trite, but illustrative of a general problem, use your imagination. To fix this problem could involve a lot of debugging, text searching, inspecting logs, etc. Then when you have to integrate your code into another department's application, you have to do it again.
In C# the compiler would immediately find all cases where the 3rd party library broke you.
Ok that was a rather winded way of saying "dynamic languages pose extra challenges for large applications". This is also true of Python. This isn't to say I don't like Javascript or Python, that can do many things that would be hard or even impossible in other languages. The asynchronous nature of Javascript lets you do a lot without multithreading and the evil, evil shared memory synchronization patterns you must use with it. At the same time, I miss the comfort of knowing my object is an apple, not not having to debug to figure out I was suddenly passed an orange.
One of the great things about Javascript is the ecosystem, and the shear massive amount of effort and work going into it. There are more Javascript libraries and frameworks and tools than one could ever learn in a lifetime. Javascript is ubiquitous,
The second aspect to Web Development that makes me marvel at it's popularity is way in which user interfaces are created, the DOM. Creating user interfaces in html is for the self-taught an execise in cooking "div soup". Go to any major modern website; Facebook, Twitter, CNN, and open the page in the dev tools in your browser off choice. Invariably, it's built with nested div upon div upon div's. The css is typically where the magic happens that makes those div actually look and behave like the site you're visiting. But it's a dark art to getting it right and authoring, that comes with experience, not necessarily the good kind. It takes years of learning the arcane quirks like "oh you need to wrap that in a div with float:left" or "oh Firefox need's explicit widths on those elements". Compared to most of the Desktop UI frameworks I've worked with, traditional web UI development feels .... irrational.
There is hope though, I think things are getting better. HTML 5 has enabled the tools needed to make vast improvements. A lot of HTML 5 is not implemented yet, and even more is still experimental or bleeding edge. Web Components offers a path to maybe one day doing away with the div soup and making a more satisfying meal. I have been experimenting with Google Polymer lately, and it's still very new, but has me excited that I might soon be able to build a browser app with markup that makes sense for a UI.
Though I never used Silverlight much, I've used it's big sibling, WPF, extensively. It had its warts for sure, but creating a UI was so much more intuitive than the div soups/css hacks of HTML we see today. It makes me sad that Silverlight, met an untimely end. I feel it's demise was more due to a shift to mobile devices and away from browser plugins, than its technical merits. There is a project that I ran across in my feeds recently, Fayde, which is a re-imagination of Silverlight in pure Javascript. I was able to get a basic UI rendering in minutes, despite never using it before. It is super-neat-o.
For those crufty programmers such as myself, with a slight allergy to new-fangled dynamic languages, there are a lot off tools to let you build Javascript applications in the language of your choice. Tools like Google Web Toolkit(Java), Emscripten(C/C++), Typescript, Dart, JSIL(C#/VB) all let you shield yourself a little bit from the idiosyncrasies of Javascript and the very loosely-typed nature of it. It used to be that "strongly typed" was generally considered a virtue in a programming language, it seems like the rise of browser based development has flipped the consensus. I predict it will come full circle once really large "SPA" web or nodejs application developers start feeling the pain of maintaining multi-million line, aged, legacy applications that were built on gentleman's agreements.
--P
[Note, I struggled to find the right title for this post, no offense to millennial engineers is meant by it. I think if you learned how to program before Google was a thing, you cut your teeth under a different set of common wisdoms than today. Some are now obsolete but others got lost to the noise of the new shiny. The merit of strong explicit contracts seems like one of those lost wisdoms these days. I'm always keeping up with the new shiny, while trying not to loose touch with my roots. Millenials are crazy-smart and talented. Now get off my lawn!]
The second aspect to Web Development that makes me marvel at it's popularity is way in which user interfaces are created, the DOM. Creating user interfaces in html is for the self-taught an execise in cooking "div soup". Go to any major modern website; Facebook, Twitter, CNN, and open the page in the dev tools in your browser off choice. Invariably, it's built with nested div upon div upon div's. The css is typically where the magic happens that makes those div actually look and behave like the site you're visiting. But it's a dark art to getting it right and authoring, that comes with experience, not necessarily the good kind. It takes years of learning the arcane quirks like "oh you need to wrap that in a div with float:left" or "oh Firefox need's explicit widths on those elements". Compared to most of the Desktop UI frameworks I've worked with, traditional web UI development feels .... irrational.
There is hope though, I think things are getting better. HTML 5 has enabled the tools needed to make vast improvements. A lot of HTML 5 is not implemented yet, and even more is still experimental or bleeding edge. Web Components offers a path to maybe one day doing away with the div soup and making a more satisfying meal. I have been experimenting with Google Polymer lately, and it's still very new, but has me excited that I might soon be able to build a browser app with markup that makes sense for a UI.
Though I never used Silverlight much, I've used it's big sibling, WPF, extensively. It had its warts for sure, but creating a UI was so much more intuitive than the div soups/css hacks of HTML we see today. It makes me sad that Silverlight, met an untimely end. I feel it's demise was more due to a shift to mobile devices and away from browser plugins, than its technical merits. There is a project that I ran across in my feeds recently, Fayde, which is a re-imagination of Silverlight in pure Javascript. I was able to get a basic UI rendering in minutes, despite never using it before. It is super-neat-o.
For those crufty programmers such as myself, with a slight allergy to new-fangled dynamic languages, there are a lot off tools to let you build Javascript applications in the language of your choice. Tools like Google Web Toolkit(Java), Emscripten(C/C++), Typescript, Dart, JSIL(C#/VB) all let you shield yourself a little bit from the idiosyncrasies of Javascript and the very loosely-typed nature of it. It used to be that "strongly typed" was generally considered a virtue in a programming language, it seems like the rise of browser based development has flipped the consensus. I predict it will come full circle once really large "SPA" web or nodejs application developers start feeling the pain of maintaining multi-million line, aged, legacy applications that were built on gentleman's agreements.
--P
[Note, I struggled to find the right title for this post, no offense to millennial engineers is meant by it. I think if you learned how to program before Google was a thing, you cut your teeth under a different set of common wisdoms than today. Some are now obsolete but others got lost to the noise of the new shiny. The merit of strong explicit contracts seems like one of those lost wisdoms these days. I'm always keeping up with the new shiny, while trying not to loose touch with my roots. Millenials are crazy-smart and talented. Now get off my lawn!]
Sunday, December 7, 2014
Stupid Simple Website Metrics
I wrote a tool that I am open-sourcing to keep track of website server performance. It is very un-fancy. It tries to do one job and do it well: Log and display page load times. (Wait, is that two jobs?)
Over the past several months, I've spent way more time than I had anticipated stressing over, testing, and trying to fix the abdominal performance I had on anibit.com. I was using a low end hosting service intended for personal websites, which I had expected to on the slower side of things, but it got so bad that page loads could take up to 45 seconds. That was even at times when I was the only user other than the failed spam-bot log ins once a minute or so. I would have been satisfied with 6 second loads even though that is considered a generally poor user experience. Something had to give. Anibit was on a shared server with probably dozens (my host service doesn't reveal that I'm aware of how many websites share your host). Any of them could misbehave and bring the server to it's knees until the hosting service brought the hammer down on them, which it frequently needed to do.
Background
Subscribe to:
Posts (Atom)
