Wednesday, 15 April 2015

Why you want to build your own platform. PAAS on top of IAAS.

The problem:

PAAS and auto-scaling are brilliant, I love them, but I hate the hidden price...Vendor lock-in.
IAAS and cloud VMs are great, I love them, but I hate the hidden price...Vendor lock-in.

Neither solution works in the long run.

Either we run into a missing facility in the PAAS, or our costs scale out of control as IAAS gains traction with the developers, testers and everyone starts spinning up VMs all over the place.

We end up creating a Heath Robinson-esque machine, solving each little problem by adding one more part to our monster.  The complexity grows and grows and grows. Soon enough no more features can be added as keeping the machine running takes all our time.

Eventually we are going to realise that we need more/better/bigger and will have to change everything or go and find it somewhere else and we still have to change everything.

So vendor lock-in is the biggest elephant in the room, and we face it where ever we look at the moment. Yes, you can have all their shiny features, but you must create everything their way, and woe betide you if you think you can change provider easily.

Everything we do becomes tightly coupled to the providers infrastructure or systems:
development, deployment, testing, roll-back, DevOps, Sysops, metrics, and the list goes on...

There are ways around these issues, but they always feel like edge case coding, and I know another edge case is waiting just around the corner, in fact I have 3 in the backlog.

Are you ready? Here are the words, just in case:
"We welcome our Heath Robinson overlords..."

The dream:

For a long time, I have had a dream ... of a system that allows everyone to get the best of all worlds, without any group suffering to support other, and everyone is capable of working to improve their conditions.
  • my applications should be able to live anywhere
    • without requiring a complete refit, refactor and rebuild just to move home
  • I can code it, test it, build it, deploy it and manage it easily, uncoupled from the infrastructure
    • No more herculean efforts just to get tests to run locally or in the build
    • Use the best of breed as standards, but avoiding the Heath Robinson effect
  • A simple configuration system that has defaults for everything, yet all can be overridden
  • Simple to change, and old parts replaced or new injected without downtime
How to do it?
This thought has bothered me for a long time.

The solution:

Eventually, I fell back on time honoured solution.
To de-couple 2 things, create an abstraction layer between them.

An Infrastructure Abstraction Platform: IAP.

Create an  abstraction layer, a platform for my code, that runs on top of any IAAS, that can manage itself, and all the applications inside it, as well as interface with the containing IAAS, but avoid coupling my applications to the IAAS. Everything external to my platform and applications should be attached through discovery and configuration, so an IAAS provider change should only require a redeploy and a config change.

If you have any idea how much time/effort this would take, you can understand my reluctance to even think about starting it. That was until I discovered Vertx.

Next:

[Coming soon: What Vertx lets me achieve]
[Coming soon: Why I use ENYO to build UIs]
[Coming soon: Why I can now build my own platform on IAAS]



Friday, 23 January 2015

Edit Makefile in Intellij

My projects now tend to use a lot of different tooling.
eg: Vagrant, docker, Node, Bower, CURL, ANT, Maven, Gradle and a bunch of other custom tools that I have to remember how to use. Worse still we are moving to mass production, so I will need to remember them across projects.

To solve this, I have recently started using Makefiles to aggregate all the command line stuff. Now I can store the rarely used commands and port them from project to project without needing to go and look them up again.

Anyway, I need to edit a Makefile in Intellij IDEA.
Easy right...

Nope, I now keep getting:
Makefile:17: *** missing separator.  Stop.

FYI: The Cause of this error: MAKE requires a TAB at the start of each command line, but Intellij has converted all TABs to multiple Spaces. You can change the Makefile to use space as indents, but it looks horrible.

Anyway, I found a few solutions, and this is mainly to remind myself. But if you happen to find this post and it helps, please let me know, or worse if it fails, do please let me know in the comments, as I will look into it.

Firstly, install the C/C++ plugin from the plugin repositories.
This adds Makefile syntax checking and highlighting.

Second: to sort out the tab converting syntax problem, open your Makefile and then...
EDIT -> Convert Indents -> To Tabs

FYI: to see the Spaces/Tabs, I used "Show Whitepaces", by...
HELP -> Find Action -> "Whitepace"
which shows the characters in the active editor.

Thursday, 7 August 2014

Easy Design-By-Contract for Java and Javascript

Why use Design by Contract?
I like a very cut down form of Design By Contract. I use it to validate the arguments passed to a function. So if an expectation suddenly fails, my code will immediately drop me into the debugger if I am developing, or throw an Error with an actual meaningful message in Production.

I have been frustrated for a while by the number of lines of code (complexity) needed to implement Design By Contract in either Java or JavaScript, or the need to use recompiling frameworks so the output code is modified.

This frustration has finally come of age, and with some help from James Gee, we have almost finished working on ExceptionExtensions for both Java and JavaScript.

There are 2 advantages to using this:
  1. It is designed to read like natural language, so code is much easier to read and write. Parameter validation in java REST interfaces, or function expectations in a JavaScript event handler, both become easy to write, and more importantly 6 months later, I can read it as easily as English, or my colleague can read it tomorrow without needing to ask me WTF?
  2. Debugging an contract expectation failure become simplicity itself. Isolating and identifying the causes of bugs is so much easier if your code simply stops at the point of failure and makes a fully scoped stack available, without the need for complex conditional breakpoints.
I know it sounds simple, but using ExceptionExtensions and Design by Contract has massively improved the readability of my code and revolutionized my ability to isolate and identify the causes of a bugs.

Java:
import static com.techmale.exception_extension.ExceptionExtensions;

public void myMethodName(String arg1, int arg2){
    IllegalArgumentException.when(arg1 == null,"arg1 is NULL");
}

To debug: Simply set a break point in the ExceptionExtensions src code and run your code in debug mode. You will drop into step debugging without needing to set up any complicated conditional debug points.

Javascript:
function myFunc(arg1,arg2,arg3){
    arg1 = arg1 || "defaultValue";
    Exception.when(!!arg2,"Arg2 is mandatory");
    Exception.when(arg2 typeof != "Number","Arg2 must be a Number");
    Exception.when(arg3 != 100,"Arg3 must be a 100, is actually %s", arg3);
    
    // .. the rest goes here
}

To debug: Just make sure your console is open, as debugging is automatic out-of-the-box. If you want to turn it off for a production system, just read the instructions on GitHub, or the post below on conditional evaluation.

The Conclusion?
The price: A really simple change to your coding practices.
The prize: A massive win for readability and super easy bug hunting.

Lastly... to download ExceptionExtensions:

ExceptionExtensions for Java
ExceptionExtensions for JavaScript






Tuesday, 1 July 2014

Conditional evaluation in JavaScript - smarter better code

I have been trying to write some very concise code recently, that has a lot of conditional checks build into it. The problem with this, is the whole thing just becomes a long set of IF/ELSE statements, which is horrible to read.

Then I had a brainwave... JavaScript allows for the conditional evaluation of any expression.

so instead of writing this:

if(myCondition==true){
    doOtherFunction();
}

I can write this

    myCondition && doOtherFunction();


or even this

myCondition && myCondition>100 && doOtherFunction();


In fact, I can chain any number of expressions together, as long as they all evaluate to true.
and, it can even include assignment, as assignment is simply an expression.

myCondition && (myOtherVar=999);

And just to put the icing on the cake, I can combine this with Cast-to-Boolean.

Boolean(myCondition) && doOtherFunction();

or

!!myCondition && doOtherFunction();


Ok, the last example is getting a little extreme, but if you are looking for concise code...



Friday, 25 April 2014

A simple pad function in Javascript

I have been working on a small time tracking tool in angularJS, and I needed padding for strings in a digital clock. I had a quick search and although I found quite a few different implementations, none of them were very satisfactory.

So, I built one.

Quite simple really, but it will handle pretty much any type of input, and will pad both left and right.

Anyway, here it is.


function pad(input,size,paddingChar,direction){
    input = String(input);
    size = size || 1;
    paddingChar = paddingChar|| 0;
    direction = direction?String(direction).toUpperCase():"LEFT";
    var padString = Array(size).join(paddingChar);
    if(input.length < size){
        if(direction == 'LEFT'){
            input = (padString+input).slice(size*-1);
        }else if(direction == 'RIGHT'){
            input = (input+padString).slice(0,size);
        }
    }
    return input;
}

It is pretty easy to use:

To get Left padding:
pad(8,2,0) will return "08"
pad("234",5,0) will return "00234"
pad("top",5," ") will return "  top"

To get right padding:
pad("top",5," ","RIGHT") will return "top  "

If you like it, please feel free to use it (at your own risk, of course).

Friday, 29 November 2013

Fixing GVM

Sometimes GVM seems to disappear, so I am writing this to remind myself of the solution.

echo $GVM_INIT
unset GVM_INIT
[[ -s ~/.gvm/bin/gvm-init.sh ]] && source ~/.gvm/bin/gvm-init.sh

basically, clear the flag and re-initialise.


Wednesday, 2 October 2013

A better way to highlight Groovy in Intellij

Following my last post, on changing the Highlighting for Warnings, I have now discovered that I can upgrade the alert generated by the code inspector.

I still have the basic problem, that I am passing the wrong variable into a method call.
And I expect my IDE to highlight it as a serious error, not a warning.

So, goto:
Settings > Inspections
Groovy > Assignment issues
Incompatible type assignments

And change Warning to Error in the Severity options.


Now, if I make the same mistake, it is immediately highlighted in my code.