Friday, September 7, 2012

jQuery UI Tabs issue in MVC 4

I was trying to set up the jQuery UI Tabs sample in an ASP.Net MVC 4 application and got the following error in the console:

Uncaught TypeError: Object #<Object> has no method 'tabs'

It turned out that jQuery was not yet loaded at the time the .tabs() method was being called.  Scripts must be loaded in the correct order or the code they're referencing may not be available.  I had the bit in the document ready block but was still having a problem. The problem in the MVC case seemed to be the mix of using both MVC bundles and script tags. There is likely a proper way to do it if I were to read more about bundles and when they're loaded, etc. 

I decided to put all the script resources into bundles and loaded them that way and I left the bit of code calling $('#tabs').tabs() in a script tag. Still no luck. So I deleted that script tag, loaded my page, made sure all scripts were available and then in the chrome javascript console I entered $('#tabs').tabs() and BAM, the tabs appeared.  This proved that the script fragments were not being run in the order I had expected so I put the code in a separate js file and loaded it in a bundle as well and everything worked.

So if you're using Bundles, it appears your best bet is to use them across the board and not mix and match with inline script tags.

Thursday, September 6, 2012

Understanding the Resistance to Agile

I have been reading some architecture documentation for a set of services that are part of a much larger system. In one section of the document, after a brief (and incorrect) description of Entity Framework, I encountered this paragraph:
This framework was chosen to support agile development. The developer does not need to write any data access logic, other than creating the entity data model, and the framework was built to work directly with the Windows Communication Foundation DataService class.
Firstly, this statement misconstrues the meaning of Agile Development. Agile Development has nothing to do with what code is written or which framework is chosen. Agile development is about enabling the developers and about being able to develop amidst a rapidly changing environment towards an often incorrectly or partially defined target. The first value defined by the agile manifesto (http://agilemanifesto.org/) states that we value "Individuals and interactions over processes and tools" yet this statement is all about choosing tools (EF and WCF).


No wonder there is resistance to Agile Development when there are people spreading falsehoods like this around.

I still can't believe what I've just read... not to mention I read it in an overly "comprehensive" 67 page document.  As if a description of EF was necessary; a link to the official Microsoft documentation on EF would have sufficed.

Monday, August 20, 2012

TFS... meh.

I've recently switched jobs and am settling in to a new work environment; learning new practices and procedures. One new thing I've been exposed to here is using Team Foundation Server for source control. I had heard it was a huge improvement over Visual Source Safe (which wouldn't take much to accomplish) but that was about the only comment I'd get from people using it.  Now that I've had a little bit of time to try it out I'm beginning to form opinions.  My first impression was that TFS has a lot more to offer than just source control and if a team were taking advantage of those additional features (like Team Build, Project Management Features, etc.) then I could see the advantages of it.  Unfortunately, just as a VCS tool it leaves something to be desired.  I'm planning to leverage Team Build and bring some continuous integration into play in the new environment here but that will be fuel for another post.

TFS First Impressions

Like the title of this post says, my general first impression was just that, "meh".  There was still a flavour of VSS with all the locks and how I have to actually "check out" a file before I can edit it.  If there is an image or a word document in the solution, for example, that I need to modify for some reason, I have to first, check the file out in Visual Studio, then open the file from windows explorer using word or whatever third party application I need to make the change after which I then check in the changes from within Visual Studio.  It all just seems so inconvenient.  I don't know how many times I've opened a file in the past week, made some changes, and tried to save them only to be told the file is read-only...  I know it's a habit and I'll eventually be broken of it, but it's still an extra step.  It slows development down.  Thankfully, Visual Studio is smart enough to check a file out for me when I start to edit it.  But if I want to open some javascript files in a text editor because I like the way that editor handles jslint or code completion or feature X, I still have the same problem.

Now the above is going to prompt comments about how there are tools like Team Explorer that have shell extensions that will let me do it from the windows explorer context menu and my reply to them would be that I've installed that but it's still a bit annoying to use. Didn't even work at first and my icon overlays don't seem to be working either... they're always the same green triangle, they don't ever change...

Merging is SLOOOOOOWWWW....

Merging conflicts is a pain which probably is why people try to work in a way to avoid conflicts at any cost. The built in merge/compare tools are lackluster and feature poor and once you've completed the merge, saving any changes takes much longer than it should and during this save operation, the strangest thing happens, all the Visual Studio windows are redrawn in the display.  They go all white for a second or two and then slowly everything comes back bit by bit. I'm not sure why this has to happen but it does.  Now I understand we're not using the most recent version of TFS but it is still strange behaviour that renders the system unusable for several seconds.

Shelving/Unshelving: great in concept, annoying in practice.

When I first read about shelving changes in TFS I thought, "oh, just like stashing in git" which is a git feature I admittedly haven't used a whole lot either. At any rate, it sounded like a useful feature and thought I'd try it out. I had been working on some code and needed to switch to something else so I figured I'd give it a go; they weren't really huge changes so I could afford to do them again if the it didn't work as I expected.  I shelved the changes, did the other work and checked it in. I didn't unshelve my previous changes immediately and came back to it a day or two later.  The unfortunate thing was that my newer changes did not work with the shelved changes and the shelved changes had no connection to the revision on which they were made which basically rendered them useless and I ended up just doing them all over again in context of the more up to date code.  I found it to be a frustrating experience mostly due to my expectations not being met.  I'm not one to give up so easily and so have continued to play with them on occasion and they have some use as long as you can work within the limitations of the feature.  I think most of my disappointment comes from the the feature not being as cool or useful as it sounded when reading about it in the documentation.

Thursday, August 16, 2012

Playing with ASP.Net MVC 4

For an intro to MVC 4 have a look at this article.  I'm enjoying the scaffolding and the Razor templates (which were released with MVC 3 but hadn't played with them yet) and the Code First approach to using Entity Framework.

Thursday, July 26, 2012

Words to live (work) by

Martin Fowler tweeted a bliki retread to his article about RigorousAgile today.  My favourite line is this one:
...agile methods fundamentally expect teams to decide what process to follow and furthermore expect teams to actively and regularly change their process.
I found it to be a very concise description of agile methods that hits those key points perfectly. It's all about continuously improving and I have yet to find an environment as rewarding to work in as being part of a team that has that outlook.

Wednesday, March 28, 2012

Decoding Base64 Encoded Strings with CherryPy

I wanted to write a simple web app for decoding base64 encoded strings.  I wanted something that was very easy to use that wouldn't require a large amount of up front learning.  I've done some stuff with Google App Engine Python SDK before and thought about using that (and I might still do that) but decided to look at some other frameworks.  I came across CherryPy which I had heard of before but never really looked at.  To get a basic Hello World app working was very quick and easy and I liked that it has a built in web server so I wouldn't have to configure Apache or some web server to get it working.  It's so minimal that it just looks like python code with embedded html and if you use something like Mako templates it looks even cleaner but it does add a little more complexity.  Mako templates are very easy to use however and if you are building larger scale applications they are well worth it.

Below is the code I came up with.  It is a simple website with 2 pages. The first is for decoding base64 encoded strings and gives you the result as a file to download.  The second is for encoding files and has a file upload form that gives you the resulting base64 encoded string as a result.

To run it, you need python and cherrypy installed (I'm using python 2.6.4 and cherrypy 3.2.2). Save the below code as base64Decoder.py and use the following command to run it:

python base64Decoder.py

And then view it in your favourite browser at http://localhost:8064/

import base64
import cherrypy
from cherrypy.lib.static import serve_file

class base64Decoder(object):
    def index(self):
        return """
        <html>
        <head><title>Base 64 Decoder</title></head>
        <body>
            <h2>Base 64 Decoder</h2> 
            <a href="encoder">Switch to Encoder</a>
            <h2>Paste in the base 64 encoded string</h2>
            <form action="decode" method="post" enctype="multipart/form-data" target="_blank">
            <textarea id="textToDecode" name="textToDecode" rows="5" cols="40"></textarea>
            Name of output file: 
            <input type="text" id="fileName" name="fileName" />
            <input type="submit" value="decode"/>
            </form>
        </body></html>
        """
    index.exposed = True

    def encoder(self):
        return """
        <html>
        <head><title>Base 64 Encoder</title></head>
        <body>
            <h2>Base 64 Encoder</h2> 
            <a href="decoder">Switch to Decoder</a>
            <h2>Upload a file to encode</h2>
            <form action="encode" method="post" enctype="multipart/form-data" target="_blank">
            filename: <input type="file" name="myFile" />
            <input type="submit" value="encode"/>
            </form>
        </body></html>
        """
    encoder.exposed = True

    def encode(self, myFile):
        cherrypy.response.headers['Content-Type'] = 'text/plain'
        data = myFile.file.read()
        return base64.encodestring(data)
    encode.exposed = True

    def decode(self, textToDecode, fileName):
        cherrypy.response.headers['Content-Type'] = 'application/octet-stream'
        dis = 'attachment; filename="%s"' % fileName
        cherrypy.response.headers['Content-Disposition'] = dis
        outstr = base64.decodestring(textToDecode)
        return outstr
    decode.exposed = True

    decoder = index

cherrypy.server.socket_port = 8064
cherrypy.quickstart(base64Decoder(), '/')