The Beauty (And The Beast) Of Code Generators

Gears 148196 640

Lately, I’ve spent a lot of time using Yeoman for generating AngularJS and MEAN applications. I’ve had a love/hate relationship with code generators for a long time, but have never really been able to articulate exactly why, so I thought I’d take a minute to write it out.

The Benefits

The benefits are easy to explain. They are the reason we use generators in the first place. They save us time. They keep developers from having simple, monotonous, plumbing code.

The prospect of writing plumbing code is enough to make and respectable developers skin crawl. We’ve written it a couple of times, and we start thinking about why we’re doing it again. Not to mention the fact that we really want to get to the interesting business problems; the problems that make the project we’re currently working on interesting. The sooner we get the basic plumbing of the app written, the sooner we can get back to those interesting problems.

I also have been using Yeoman generators to learn more about how people are writing AngularJS and MEAN-stack applications. I generate the base application and then read the code. I look at how they configure the app, how they wire things together and how they accomplish things that feel difficult to me. This is another great use of generators and something I recommend to lots of folks I come across who want to learn more about building Angular or MEAN-stack applications.

The Drawbacks

The drawbacks come in two causes: ignorance and regeneration.

There are quite a few developers that generate code without any idea what the code does or whether the code does it well. This leaves behind code that may be inefficient, possibly poor performing and sometimes almost unmaintainable. Also, since the developer that generated the code doesn’t know how it works, it can be quite impossible for them to modify it for specific business rules.

The other problem is that some code generators generate code that is meant to be regenerated. These are usually ones based off of a database schema. When the schema changes, the developer is meant to regenerate the code for the new schema. This is okay, but once the schema gets large or complicated, regeneration can be tricky. If a certain set of expectations aren’t met (incorrectly assigned keys, relationships, etc.), regeneration can yield unexpected code. Code that doesn’t work or works in unexpected (and unintended) ways, leaving the developer to either dig through the generated code or dig through the generators documentation to figure out what she did wrong in the schema to make the generators generate this unexpected code.

The Conclusion

Generation is good, but only if you understand what’s being generator (or are generating so you CAN understand it). Regeneration is bad, or at least iffy.

I tend to stick to generators for one of two reasons: to generate code to read and learn, or to generate code as a “jumping off” point. I fully intend to start modifying the generated code for my specific use case as soon as I am done generating it. This also make regeneration an unattractive option as it would overwrite my changes.

Happy coding!

When To Use ‘use strict’

Nun with Ruler dreamstime_12895823Everyone knows (or should know) that it is a better practice to use ‘use strict’ in their JavaScript code, but not everyone knows how best to use it. It can be detrimental to use it incorrectly. The most important thing is to not use it in the global scope (which is true of almost everything in JavaScript). Below is an example of how I see a lot of folks use it (incorrectly).

‘use strict’;

function someFunction(){
    //.. this function does something

What’s the problem with that? The fact that it is in the global scope is important because it will apply to all JavaScript files you bring together. Remember, you are likely including a bunch of scripts in the page where you are using this script. It will run ALL JavaScript in “Strict Mode” when this expression is used. So again you might say, “What’s wrong with that?” Assume you’ve brought in a third-party library that is not written with strict mode in mind (either because they don’t know about it, or because they needed to do something that strict mode would not allow). This code will start failing, and if you’ve ever dug into a bug in a large JavaScript code base, you know how painful that can be. The proper way to use it?

function someFunction(){
    ‘use strict’;
    //.. this is where the code works

Now the ‘use strict’ expression is only applied to the function scope, and any other code included in other JavaScripts is not affected. It’s important because if you start seeing code in a third-party library that starts failing, you might check to see if you’ve placed the ‘use strict’ in the global scope.

You might think of this as a code smell. I mean, if code you’ve brought in from a third-party library failed because of a globally-scoped ‘use strict’, you might want to look for another library. I’m just saying.

St. Louis Days of Dot Net Wrap-Up

The Conference

This year’s St. Louis Days of Dot Net was, as usual, one of my favorites of the year. My company, AdventureTech sponsored this year, so I didn’t get much of a chance to attend sessions, but I know most of the speakers and they are the best in the industry.

I gave a talk on Building a ReSTful API using NodeJS and MongoDB. Being that the topic is more fringe than normal, I expected a small turnout. I got anything but. Even though I was in a smaller room, all the seats were full and there were folks sitting on the floor. This was the first time I had given this talk and it seemed to go well. I got lots of great questions and the attendees seemed very engaged. 

We got lots of engaging conversation at our sponsor booth and there were also some great technical conversations in the halls during the conference.

The Nightlife

The conference is held at the Ameristar Casino and Resort in St. Charles, MO. The Bottleneck Blues Bar has become a pre-conference routine for us. I enjoy cigars quite a bit and being able to smoke them indoors at the tables outside the bar is outstanding. We sat and talked and smoked and drank. We had great conversations and reunited with friends from across the country we hadn’t seen since last year’s STLDODN.

The Attendee party was at the Lixx Night Club. They had casino games, food, drinks and music. After the party, a few of us retired to my hotel room (the rooms at the casino are HUGE and also smoking friendly) to drink and talk until early morning.


The organizers of this conference put on a great show every year. I can always plan on having a great time, reunite with friends I only get to see in St. Louis, and get some great technical content. Looking forward to this conference next year!

Iowa Code Camp Wrap-Up

The Conference

The Iowa Code Camp fall edition is held on the western side of the state, in West Des Moines. This was my fourth or fifth time speaking at Iowa Code Camp. Every time, this conference gets better. The speakers are all top-notch and the topics are all useful. There was a good mix of the practical and theoretical and some mainstream topics along with some fringe topics. 

I did a talk on the basics of the KendoUI framework. I have been using and enjoying the framework more and more. I had quite a few people in my talk and it seemed to go very well. 

I attended Cory House’s Single Page Application talk, Mike Benkovich’s Developer Evangelist talk and spent lots of time meeting with and discussing software development with lots of attendees and organizers in the lounge at the conference. 


As usual, Iowa Code Camp delivered a first-rate conference at no cost to the attendee. Bravo guys, bravo.

NYC User-Group Tour Wrap-Up

Upstate NYLast week, I toured up-state New York’s .Net User Group community. I spoke about KendoUI and got to meet a lot of great folks in New York state. I have to say, as cliche as it may sound, the foliage really is beautiful in the fall in up-state New York. The people were awesome and the pizza is not to be missed.

First, was Albany and the Tech Valley .Net User Group. I flew in at 4pm and by the time I got my car and got to the meeting space, it was just about time for the meeting to start. Chris Miller and the guys at Tyler Technologies that hosted the meeting are avid KendoUI users and so we had some great conversations about how they use KendoUI. Everyone at the meeting was knowledgable and engaged. Unfortunately, I didn’t get to stay too long after the meeting and socialize as I had to hit the road and head to Syracuse for Tuesday’s meeting.

Syracuse saw me at the New Horizons in East Syracuse for the CNY .Net Developers meeting. Andy Beaulieu is the leader of the group and the organizer of the tour, so a BIG thanks to Andy for that. The group, again was engaged and (I think) really interested in KendoUI in particular. A very smart group of developers passionate about software for business. I hung out for a few minutes afterward to give away some KendoUI stress balls and KendoUI Mobile licenses, and then headed to Rochester for Wednesday’s meeting.

Wednesday’s meeting of the Visual Developers of Upstate New York was held at New Horizons in Rochester. So sorry to hear about the passing of their UG leader Bob Nims. My understanding is that he WAS the user group. Steve Maier, who is a Microsoft Evangelist, headed up the meeting that night and we had a moment of silence to remember Bob. The group was again engaged and interested. The question ranged from entry to advanced level and I could tell that some of the folks used KendoUI in their daily work. I also got to meet Lou Gramm’s keyboardist! I got a chance to hang out after for a bit and then off to Buffalo!

My final stop was the Microsoft Developer’s of Western New York in Buffalo. Rich Nalezynski, the group’s leader met me at Buffalo Compter Graphics and we got all set up. Buffalo was definitely the largest crowd. The screen was immense as well. Some good local pizza for the meeting and I was off and running. Again, I had some folks who were new to KendoUI and some old-hats. There were compelling questions and some really good suggestions for future presentations. Afterward, I did get a chance to go to Duff’s Famous Wings in Depew for some world-famous Buffalo Wings. They are not the originators but, I was told, were just as good and they were close to my hotel. Rich and I had a beer, some wings and talked about software development and the future.

Just a great tour and great folks. I would love to do this tour any time! Thanks to Andy Beaulieu for organizing it and to Telerik for making it possible!


FitcLast week, I had the privilege of speaking in Toronto at FITC:SCREENS 2013, and I gotta say I was blown away. Blown away by the city, blown away by the people and blown away by the conference. Being a conference organizer myself, I will be stealing some ideas from this conference.

I did a presentation on the basics of KendoUI and it seemed to go really well. The audience was engaged and the questions afterward were thoughtful. Thanks to all who attended my session. The presentation is available here.

I didn’t get a chance to attend too many sessions, travel & work wouldn’t allow it, but I did get to see a talk by a couple of guys from Blackberry’s developer relations division on ECMA5 and using Require.js to build an inheritance model. It was super interesting and well done.

The conference eon the whole was very well done. Kudos to the FITC: SCREENS team for an outstanding conference, and I hope to get a chance to come back and speak next year!

Nebraska Code Camp Wrap-up

This past weekend, I was priviledged to speak at the Third-Annual Nebraska Code Camp in Lincoln, Nebraska.

The Conference

The conference garnered about 300 attendees from all over the region. There were talks about UX, the cloud, mobile, web and desktop development of all types from some of the regions most talented developers and speakers.

The highlight of the conference was a keynote by Ted “Theodore” Neward. As usual, Ted delivered a keynote that made you think and introspect. Ted talked about “Rethinking ‘Enterprise’” in which he asked and (almost) answered what ‘Enterprise Software Development’ should mean to each of us. I won’t spoil the ending. Suffice it to say, I AM rethinking ‘Enterprise’.

I also attended Ted’s Esoteric Languages session. It was fun and informative. Probably the most I’ve ever laughed in a code camp session.


Regardless what might come to mind when picturing Lincoln, Nebraska, it is a simple, college town. We headed to Barry’s for the attendee after-party, where there were snacks and beverages.

We then headed to Jake’s Cigars & Spirits for cigars and beer. Being an avid cigar smoker this was definitely the highlight of MY night.


Another excellent year for Adam Barney and Ken Versaw, the organizers of Nebraska Code Camp. The sessions we excellent and the after-party was epic (as usual). Thanks to all who attended my session and thanks to the sponsors for helping make it another excellent year. Can’t wait to submit for next year!

Fake It Easy On Yourself

I have been using Rhino.Mocks pretty much since I started being a mockist-type tester. I have been very happy with it for the most part, but a year or so ago, I got a glimpse of some tests using Moq. I thought the little bit I saw was very compelling. For a long time, I had been using:

   1: var _repository = MockRepository.GenerateMock<IRepository>();

   2: _repository.Expect(repo=>repo.SomeCall()).Return(SomeValue);

   3: var _controller = new SomeKindaController(_repository);


   5: ... some exercising code

   6: _repository.AssertWasCalled(repo => repo.SomeCall());

I was happy with that syntax. I didn’t go looking for something else, but what I saw was:

   1: var _repository = new Mock();

And I thought, “That looks really nice!” The code was very expressive and easier to read that the Rhino.Mocks syntax. I have gotten so used to the Rhino.Mocks syntax that it made complete sense to me, but to developers I was mentoring in mocking, it was sometimes to obtuse.

SO I thought I would write some tests using Moq as my mocking tool. But I discovered something ugly once I got into it. The way Mocks are created makes Moq very easy to read, but that only gives you a Mock not the object itself, which is what you’ll need to pass to the exercising code. So this is what it ends up looking like:

   1: var _repository = new Mock<IRepository>();

   2: _repository.SetUp(repo=>repo.SomeCall).Returns(SomeValue);

   3: var _controller = new SomeKindaController(_repository.Object);

   4: .. some exercizing code

   5: _repository.Verify(repo => repo.SomeCall());

Two things jump out at me: 1) when I set up my mocked calls, do I set it on the Mock or the Mock’s “object”? and 2) What am I verifying on SomeCall? Just that it was called? that it is available to call? Dealing with 2 objects, a “Mock” and an “Object” made me have to consider naming conventions. Should I always call the mock _repositoryMock and the object _repository? So I went back to Rhino.Mocks. It is the most widely used framework, and show other how to use it is easier because there is one natural object to use, the _repository.

Then I came across a blog post from Patrik Hägne, and that led me to a post about FakeItEasy. I went to the Google Code site and when I saw the syntax, I got very excited. Then I read the wiki page where Patrik stated why he wrote FakeItEasy, and it mirrored my own experience. So I began to play with it a bit. So far, I am sold. the syntax is VERY easy to read and the fluent interface is super discoverable. It basically looks like this:

   1: var _repository = A.Fake<IRepository>();

   2: a.CallTo(repo=>repo.SomeMethod()).Returns(SomeValue);

   3: var _controller = new SomeKindaController(_repository);

   4: ... some exercising code

   5: A.CallTo(() => _repository.SOmeMethod()).MustHaveHappened();

Very nice. But is it mature? It’s only been around a couple of years, so will I be giving up some thing that I use a lot because it hasn’t been implemented yet? I doesn’t seem so. As I read more examples and posts from Patrik, he has some pretty complex scenarios. He even has support for VB.NET!

So if you are looking for a mocking framework that looks and feels very natural, try out FakeItEasy!

503.1 Service Unavailable Error Resolution

I was having a hell of a time tonight with my IIS on my development laptop. I don’t remember doing anything to change the IIS settings. I don’t use IIS that much on my dev machine. Usually Cassini is enough for testing my development efforts but tonight I needed to replicate a problem that seems to stem from x86 v x64 mismatch, so I went to create an IIS site pointed to my dev folder.

When I did, I got a “503.1 Service Unavailable Error”.

First thing I did is go over all my setting to make sure I didn’t screw something up when I set up the site. It was pointing to the right place, and the app pool settings seemed to be alright. However, when I got the 503.1 error and went back to my app pool list, I saw that the app pool I was using was stopped again. I must’ve started and ran it a dozen times to verify that I wasn’t seeing things. After having a colleague look at it and not finding an answer, I started poking around Google. I cam across a post from Phil Haack about the same error. His fix was not mine, however. When I ran his command on the CLI, I didn’t see the reserved routes for HTTP.SYS there.

Finally, I looked in the event viewer (where I should have looked as soon as I saw that my app pool was stopping) and saw an error in there. For the IIS-W3SVC-WP Source I saw:

The worker process for application pool ‘DefaultAppPool’ encountered an error ‘Cannot read configuration file due to insufficient permissions

‘ trying to read configuration data from file ‘\\?\C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config’, line number ‘0’. The data field contains the error code.

So I went to that path and saw a little lock on the file icon. I opened up the security tab for file properties and saw that I was missing the IIS_IUSRS group. On a machine that was working correctly, I verified that it indeed had the IIS_IUSRS group set to Read and Read & Execute allowed. So I set mine up the same and voila!

Hopefully this helps somebody else, too.

Enhanced by Zemanta