Friday, August 28, 2015

Battle of the Languages

One great thing about the challenges offered on is that they can be solved in so many languages - e.g. choose the language of your choice and go at it! As a side benefit, one can easily compare run-times and memory footprints of languages by solving a challenge in many languages and viewing the results. As an experiment I did just that with the following challenge.

Here is the description of the challenge, as it can be seen on the site:

And the basic solution, which I implemented using the same basic algo in five languages (JavaScript, Java, PHP, C#, and C).

The test data is supplied via a file passed to args during execution, the same file is used in every execution run. JavaScript is run on Node. Execution takes place server side on a Linux based server (more details on the CodeEval site).

Basic algo is: for each line, split line on comma, parse each val to an int, run computation, print results to standard output.

Drum roll please....

As expected, C has the smallest mem usage and the fastest run-time, and by far at that. But I didn't expect Java to be that bad. Granted this is a trivial example. It would be interesting to see if the gap closes when the C program needs more supporting code. Educated guess is yes but not by much. The Java code for is below, I wonder if I'm doing anything wrong here or if it really is that less efficient in all ways.

public class Main {
    public static void main (String[] args) throws IOException {
        File file = new File(args[0]);
        BufferedReader buffer = new BufferedReader(new FileReader(file));
        String line;
        while ((line = buffer.readLine()) != null) {
            line = line.trim();
            String[] vals = line.split(",");
            int x = Integer.parseInt(vals[0]);
            int n = Integer.parseInt(vals[1]);
    static void compute(int x, int n)
        int m = n;

I plan on doing this same test in Ruby, Python, and GO to do an even broader comparison, when I have some time. Results will follow if I do.

Thursday, August 27, 2015

EF natural keys and duplicated properties

While working with a VS solution that has been around for about 6 years, an issue was brought to my attention regarding duplicate records from a query. The solution uses and old version of Entity Framework and ties the results of an imported stored procedure to a web forms control (data grid, repeater, or similar). The entity type is based on and mapped to the returned data table from the stored procedure.

A more concrete example would be a Teacher entity with three properties [Name, Classroom, School].

The results of the stored procedure represented below:

June Ward, 102, James Woods High School;
Fiedora Vilma, 233, MLK High School;
Fiedora Vilma, 126, MLK High School;

Were showing up in the app as:

June Ward, 102, James Woods High School;
Fiedora Vilma, 233, MLK High School;
Fiedora Vilma, 233, MLK High School;

Notice that 233 is repeated for the last 2 rows.

Upon investigation of the Teacher entity via the model designer, I saw that only the FullName property was designated as the entity key. But it seems as if the natural key in this set would need to be the FullName and ClassroomNumber.

> Highlight FullName, properties, set entity key false.
> Highlight FullName AND Classroom, properties, entity key true.

now the combo key is shown. Rebuild solution, check to see and the classrooms are no longer repeated.

Wonder if this was "fixed" in some later version of either EF or ASP.NET. Anyways, the solution is fixed for now.

Wednesday, August 19, 2015

Here's a Challenge!

If you haven't done so already, join Code Eval
it's a great way to brush up or learn a new language. There are challenges which can be solved using the language of your choice. Its kind of like a game, you earn points and get ranked. There are sponsored challenges and potential for finding jobs. When you do this, find me "philn5d".

There's another site called Top Coder with challenges. This one has payouts for sponsored challenges, but also pure algo challenges. The sponsored challenges are companies paying to have some work POCd or perhaps actual implementations. Given that, the payouts are actually really low considering what they would pay a contractor and you'd have to place top 2 or 3 for a payout. But, there are really interesting challenges, most of which are technology constrained. Give it a try, you may like it and may earn a few dollars in the meantime it is free to join.
I'm on there too.

For a Good RDRR try LOLCODE

Seriously, if this isn't old news to you, "go to bing and type g o o g l e then execute the search. Click the link that takes you directly to and search for" LOLCODE. Wikipedia has all the dirt.

If, for some strange reason, you would like to drive yourself mad for a bit - go to
this is the best thing since mouse pads. Seriously, they have TONS of online editors that really don't suck too badly. I've found quirks in some execution engines, but really this is a great way to learn or POC from anywhere!

Btw, the quote is modified from the famous "how I met your girlfriend" video.

msdn xand something exciting

First, I'd like to gripe for just a minute. I've been receiving MSDN magazine in the mail for a few years now due to it's part of the subscription package that my current place of employment maintains. Cool. I get it. Here's our latest thing we are doing and how to use it. My gripe is that it's more or less the same thing now - here's how to do some basic shit using Azure. Use Azure. Here's some awesome pattern, and btw here's how to use it on Azure. It's basically a monthly sales pitch for Azure. Kudos for the advertising tactics, MS is really going hard into this one and it makes sense. It's just getting a bit old is all. I've demoed Azure and its not bad (when it isn't completely frustrating due to something being down or taking forever or not responding). Oh I generally do the free thing or the low-cost option, and yeah its lower in the priority queues for processing. But hey, its my experience so far - not making me want to fully commit though.


Then there's at least one article that is just pure and clean. This month's is about 3D Web Games using JavaScript (Three.js). Awesome! I've had it from other sources that a guy in the Netherlands or thereabouts (Anders Evenrud) built A FUNCTIONING OS IN JAVASCRIPT! So... Anyways check that out at
and contemplate that for a bit. And he even has a badass name! This guy is my hero.

Thursday, August 6, 2015

What is the Future of Software Development

With advances like TDD, BDD, IBM's Watson, and Microsoft Cortana what will the future hold for software development?

Today, we can write automated tests to validate design and implementation. If we're doing this in an optimal way, then we are writing the automated tests to specify the system. What if the next level is to write only the tests and not the code? What would that look like?

I would imaging that the tests would have to be written very specifically to define every aspect of the system including environmental considerations. It would certainly take the saying "the tests are the requirements, the requirements are the tests" into another form. Something like "the requirements are the system, the system is the requirements."

This would require some clever sort of meta-programming model that could take a ubiquitous definition of the the system defined by example and translate it into whatever language. Some sort of translator/code generator/compiler would take the BDD style requirements and, ultimately, turn them into runnable applications.

First, the spec reader would need to parse the requirements into a standard baseline. With that, any BDD style format could be used as input, given the proper translations.

Next, something would need to analyze the baseline and decide how to efficiently process each set of rules. Perhaps some decisions would be made with respect to which language to use to maximize system efficiency and conform to the defined standards.

In order to meet those goals, certain meta-information would be needed about the system itself and about each requirement/feature. For example, one may define the security requirements of the system as a whole, or one particular feature or function. The data retention policy would be another aspect of the system. How about accessibility or internationalization? How about defining the environment constraints? Will there be a multiple environments? Or only one? Will it need to scale out?

Obvious complexities aside, I believe we have the technology and the know-how necessary to build such a system today. However, I also believe such a system designed this way would be fraught with the same problem that today's systems have and that's about the requirements themselves.

Let's assume, for sake of retaining optimism, that we provide accurate statements about every aspect of the system - what it runs on, how it will be available, what data it will use and persist, what transactions, how many users, which locations are the users, what roles, features, integrations. We define every aspect in our acceptance tests. Then those are translated, processed, and some machine or IL code is produced as a result - it's installed or deployed and we're up an running without writing a single line of code. We've only written pre-conditions, actions, and expected results. For a Given Condition, When some Action, Then some Result.

What would the first requirement look like? Would we define system constraints first? Would we define outputs first? Inputs? When would those be compiled? We wouldn't exactly have code to verify with the tests, so perhaps it would be real time, but the analysis process would take so much time especially at first.

Let's assume we would define the environment first. Given a growing population of users, And the users are geographically distributed, When users need to use the system, Then they would use a web browser. But should we even need to define that? Perhaps the compiler would know which platform would be best based on how we define the users, so we'd start there.

Given a globally distributed population of users, When the users access the application, Then they should be able to access the application from any location. With this spec in mind, the system may decide that a distributed system with multiple types of clients would be the best design. There may be decisions to make about caching on clients due to lack of specification about internet connectivity, so the only design must support with and without internet. Perhaps the compiler would need to make certain assumptions or respond with prompts. Perhaps certain parts of the design are better served as wizard-like or key-value pair configurations.

How about data, how would data be defined? In Cucumber BDD, input data is defined in either a Given statement or a Setup for a feature. But multiple features may share the same entities, so we wouldn't want to have too many definitions of them. Perhaps some tag could be used and all those related bits of data can be correlated by that.

In any case we can see that this is possible, but the details are fairly complex. It will be slow and cumbersome at first, but in time will be the usual way of building systems.