So you're using the nodejs modules express and jade, and you're posting some form data, and you can't work out why 'req.body' is undefined.
You've read the docs, and you're using app.use(express.bodyParser()) and its not working still.
You're config looks like this :
But you need it the other way round, like this :
What you've done wrong is have the bodyParser() line after the app.router line.
Make sure you put the bodyParser() line before the app.router line, and you're gravy.
Note that after a twitter exchange with the express developers, this isn't a bug, but a feature of express's middleware config - a side-effect of the flexibility of their middleware injection.
This 'fix' works for me - I'm pretty new to express, so I've no idea on the impact on other middleware you may have configured.
I'm sure after more playtime with express I'll understand why routing config blat's body parsing if done in that order.
PS - If anyone does know the answer, I'd welcome a full explanation, or link to the docs on it.
Friday, 27 January 2012
Wednesday, 25 January 2012
Nodejs Tedious Sql Server Driver and GUID / UNIQUEIDENTIFIER
So you're using SQL Server / SQLEXPRESS with nodejs for some odd reason, and you're trying to pull back Ids from a table that is has the field declared as UNIQUEIDENTIFIER, but you keeping getting an error like :
Unrecognised data type 0x24 at offset 0x0009
But its OK when you pull back nvarchar's etc.
Nasty hack that works (considering js doesn't know what a GUID is anyway) :
Change :
select Id from table
to:
select convert(varchar(38) , Id) from table
and all is well.
Unrecognised data type 0x24 at offset 0x0009
But its OK when you pull back nvarchar's etc.
Nasty hack that works (considering js doesn't know what a GUID is anyway) :
Change :
select Id from table
to:
select convert(varchar(38) , Id) from table
and all is well.
Tuesday, 5 July 2011
The debate on software craftsmanship
So this one keeps rumbling on. Are programmers software craftsmen ? Are we employed to execute a craft ? What does that even mean ? If it is a craft, does that mean some people are not in the club ? Does it matter if we are ? Or are not ?
I've written some really shit code over my years, and I've written it for some terrible reasons. And some good reasons. What do those reasons mean as a person ? Or a programmer ? Or a craftsmen ?
I've written code that was crap for the following main reasons :
1) I didn't know any better, and was doing as best I could
2) I was under krazy-with-a-K timescales, the company didn't give a rats arse about quality, and just wanted it, *anything*, out the door
3) I was lazy and/or disinterested in the task at hand
Uncle Bob (and I'm a big fan - "Clean code" was a wake-up call for me a few years ago) would most likely say that those 3 reasons for writing crap code are what made me not a craftsmen - I was a disgrace to my name as a programmer.
He wants to be able to distinguish between script monkeys banging out that kind of crap code, and the people who actually give a rats arse. And fair play to him - I get the sentiment.
Dan North would also say those 3 reasons for writing crap code are inexcusable too - but for differrent reasons. I'm guessing his argument would be that none of those reasons for writing code was actually focused on business value. If I understand his position (and I may not!), he would possibly argue that the main reason for writing code is to give the business employing you value - in terms of cost, return, and investment.
What's funny is that to me, I would guess (and I say guess, because this is all just conjecture - I don't actually know Mr North or Mr Martin) that both of those guys would agree that code should be focused on business value/deliverables, and also on code quality.... with a slight caveat ....
Business value isn't always equal to code quality. It *usually is* - but not always.
(Side topic - who the frick makes that decision eh ? Most times a dev makes it, they've got it wrong in my experience).
So why all the hoo-ha ? Who gives a frick if we're craftsmen or not ? Well, Uncle Bob and Dan North seem to, but I just don't get why.
As I see it, crap coders will write crap code all the time. Thats not a craft, nor is it adding business value.
Good coders will write good code, that adds business value.
Good coders, under pressure, will mostly write good code, sometimes crap code.
Great coders under pressure will write crap code - but will go and fix it asasp - and will lay awake at night, worrying about it.
Now to me suddenly, that does sound like a craft - in as much as novices do crap stuff, intermediates do much good stuff, experts write great stuff most of the time (no-one writes good stuff all the time).
There was a talk that Dan North did ages ago that talked about the transition from novice to expert - its a sociology thing ... can't remember it right now - think it was a oredev 2008/9 talk.
Good coders focus on the value to the business.
If we're good coders, then we use the principles laid out in "clean code", and other great books by luminaries in the programming world. We adhere to SOLID (unless we have a reason not to), we employ our refactoring techniques, we test our code, we drive our code from the business endpoint. We are "craftsmen" by default. But are we ? Are we not just doing *** our job ***. Surgeons don't get a pat on the back and a badge just because they did their homework on (sorry, I don't mean it) "best practice", and keep their tools clean and sharp. You know what they get ? They get "yeah - you did your job ... again. Cheers. Next please".
We're not l33t mofos that are at one with the ways of the coding ninja.
We've got a job, that some of us enjoy, and some don't.
Good companies hire good programmers.
Shit companies hire shit programmers (and good ones sometimes).
Being good at your job doesn't make you a craftsmen, it just makes you good at your job. It doesn't mean you can't take pride in your job, or mean you can't consider yourself to be expert (or journeyman, or novice or whatever). It just means we're doing a job like any other - its just that the people best at our job are the ones that are in-tune with the business, and also know how to write clean code.
I've written some really shit code over my years, and I've written it for some terrible reasons. And some good reasons. What do those reasons mean as a person ? Or a programmer ? Or a craftsmen ?
I've written code that was crap for the following main reasons :
1) I didn't know any better, and was doing as best I could
2) I was under krazy-with-a-K timescales, the company didn't give a rats arse about quality, and just wanted it, *anything*, out the door
3) I was lazy and/or disinterested in the task at hand
Uncle Bob (and I'm a big fan - "Clean code" was a wake-up call for me a few years ago) would most likely say that those 3 reasons for writing crap code are what made me not a craftsmen - I was a disgrace to my name as a programmer.
He wants to be able to distinguish between script monkeys banging out that kind of crap code, and the people who actually give a rats arse. And fair play to him - I get the sentiment.
Dan North would also say those 3 reasons for writing crap code are inexcusable too - but for differrent reasons. I'm guessing his argument would be that none of those reasons for writing code was actually focused on business value. If I understand his position (and I may not!), he would possibly argue that the main reason for writing code is to give the business employing you value - in terms of cost, return, and investment.
What's funny is that to me, I would guess (and I say guess, because this is all just conjecture - I don't actually know Mr North or Mr Martin) that both of those guys would agree that code should be focused on business value/deliverables, and also on code quality.... with a slight caveat ....
Business value isn't always equal to code quality. It *usually is* - but not always.
(Side topic - who the frick makes that decision eh ? Most times a dev makes it, they've got it wrong in my experience).
So why all the hoo-ha ? Who gives a frick if we're craftsmen or not ? Well, Uncle Bob and Dan North seem to, but I just don't get why.
As I see it, crap coders will write crap code all the time. Thats not a craft, nor is it adding business value.
Good coders will write good code, that adds business value.
Good coders, under pressure, will mostly write good code, sometimes crap code.
Great coders under pressure will write crap code - but will go and fix it asasp - and will lay awake at night, worrying about it.
Now to me suddenly, that does sound like a craft - in as much as novices do crap stuff, intermediates do much good stuff, experts write great stuff most of the time (no-one writes good stuff all the time).
There was a talk that Dan North did ages ago that talked about the transition from novice to expert - its a sociology thing ... can't remember it right now - think it was a oredev 2008/9 talk.
Good coders focus on the value to the business.
If we're good coders, then we use the principles laid out in "clean code", and other great books by luminaries in the programming world. We adhere to SOLID (unless we have a reason not to), we employ our refactoring techniques, we test our code, we drive our code from the business endpoint. We are "craftsmen" by default. But are we ? Are we not just doing *** our job ***. Surgeons don't get a pat on the back and a badge just because they did their homework on (sorry, I don't mean it) "best practice", and keep their tools clean and sharp. You know what they get ? They get "yeah - you did your job ... again. Cheers. Next please".
We're not l33t mofos that are at one with the ways of the coding ninja.
We've got a job, that some of us enjoy, and some don't.
Good companies hire good programmers.
Shit companies hire shit programmers (and good ones sometimes).
Being good at your job doesn't make you a craftsmen, it just makes you good at your job. It doesn't mean you can't take pride in your job, or mean you can't consider yourself to be expert (or journeyman, or novice or whatever). It just means we're doing a job like any other - its just that the people best at our job are the ones that are in-tune with the business, and also know how to write clean code.
Thursday, 23 June 2011
Ranges header with Silverlight HttpWebRequest
Trying to download a large piece of content, and using the Ranges header to do a pause/resume feature or recover from a network problem during download ?
If you're using Silverlight, and using the HttpWebRequest, you'll find that the Ranges header is not allowed! WTF Silverlight team ?
All is not lost though - more magic settings come to your aid. Before creating the request, add these two magic little lines :
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);
This works in SL4 (think it works in SL3 too)
If you're using Silverlight, and using the HttpWebRequest, you'll find that the Ranges header is not allowed! WTF Silverlight team ?
All is not lost though - more magic settings come to your aid. Before creating the request, add these two magic little lines :
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);
This works in SL4 (think it works in SL3 too)
Sliverlight SMF smooth stream player
Can't get your silverlight player to play smooth stream ? Driving you mad ? Yup me too, and this aint the first smoooth stream player I've written ... but not having access to the code for the previous ones, it was driving me crazy.
I kept getting the dreaded AG_E_NETWORK_ERROR 4001 - very helpful.
Anyway, all is not lost. If you're using the SMF (Silverlight Media framework) player as the base player, check you have the following references :
Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming.dll
Microsoft.Web.Media.SmoothStreaming.dll
And also, make sure you have this magic setting when setting up the PlaylistItem :
DeliveryMethod = DeliveryMethods.AdaptiveStreaming
MyPlayer.Playlist = new ObservableCollection {
new PlaylistItem
{
DeliveryMethod = DeliveryMethods.AdaptiveStreaming,
MediaSource = new Uri(url)
}
};
I kept getting the dreaded AG_E_NETWORK_ERROR 4001 - very helpful.
Anyway, all is not lost. If you're using the SMF (Silverlight Media framework) player as the base player, check you have the following references :
Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming.dll
Microsoft.Web.Media.SmoothStreaming.dll
And also, make sure you have this magic setting when setting up the PlaylistItem :
DeliveryMethod = DeliveryMethods.AdaptiveStreaming
MyPlayer.Playlist = new ObservableCollection
new PlaylistItem
{
DeliveryMethod = DeliveryMethods.AdaptiveStreaming,
MediaSource = new Uri(url)
}
};
Monday, 20 June 2011
51 Degrees mobile redirect and Orchard CMS
51 Degrees current version doesn't support Orchard CMS at its current version (1.0.4.1).
This is because part of the "should I redirect this page for the current request?" logic is slightly flawed.
Part of the logic checks that the request context's http handler class type is in the following list (or has a base type of an item in the list):
internal static readonly string[] PAGES = new[]
{
"System.Web.UI.Page",
"System.Web.Mvc.MvcHandler",
"System.Web.Mvc.MvcHttpHandler",
"System.Web.UI.MobileControls.MobilePage",
"System.Web.WebPages.WebPageHttpHandler",
};
Thats not going to work for Orchard, because it's http handler does not inherit from any in the list.
So the fix is to alter the list as so :
internal static readonly string[] PAGES = new[]
{
"System.Web.UI.Page",
"System.Web.Mvc.MvcHandler",
"System.Web.Mvc.MvcHttpHandler",
"System.Web.UI.MobileControls.MobilePage",
"System.Web.WebPages.WebPageHttpHandler",
"Orchard.Mvc.Routes.ShellRoute.HttpAsyncHandler",
"Orchard.Mvc.Routes.ShellRoute+HttpAsyncHandler"
};
The list is in the class FiftyOne.Foundation.Mobile.Redirection.Constants - which is in the file named RedirectionConstants.cs
It's not a great fix - but thats because the code is breaking OCP quite severly, and I don't have time to fix right now.
Hope this post saves someone else several hours of debug !
This is because part of the "should I redirect this page for the current request?" logic is slightly flawed.
Part of the logic checks that the request context's http handler class type is in the following list (or has a base type of an item in the list):
internal static readonly string[] PAGES = new[]
{
"System.Web.UI.Page",
"System.Web.Mvc.MvcHandler",
"System.Web.Mvc.MvcHttpHandler",
"System.Web.UI.MobileControls.MobilePage",
"System.Web.WebPages.WebPageHttpHandler",
};
Thats not going to work for Orchard, because it's http handler does not inherit from any in the list.
So the fix is to alter the list as so :
internal static readonly string[] PAGES = new[]
{
"System.Web.UI.Page",
"System.Web.Mvc.MvcHandler",
"System.Web.Mvc.MvcHttpHandler",
"System.Web.UI.MobileControls.MobilePage",
"System.Web.WebPages.WebPageHttpHandler",
"Orchard.Mvc.Routes.ShellRoute.HttpAsyncHandler",
"Orchard.Mvc.Routes.ShellRoute+HttpAsyncHandler"
};
The list is in the class FiftyOne.Foundation.Mobile.Redirection.Constants - which is in the file named RedirectionConstants.cs
It's not a great fix - but thats because the code is breaking OCP quite severly, and I don't have time to fix right now.
Hope this post saves someone else several hours of debug !
Wednesday, 20 April 2011
Open Source Software - my mullings
I spent 8 years running an open source software project - so I kind of have an idea what its like. Maybe I don't - maybe I just know what its like running an OSS project that is small.
I pushed some software OSS because, at the time (and this was back in 2002), I felt the best competitors at the time were buggy, and feature poor. I thought people would benefit from my software, and I think some people did.
I had some big people using it at some point - Xerox and Maersk were the biggest I think.
But mostly, it was fairly small companies, just looking to solve a problem they had, like me.
I wrote a Java connection pool - it was going against the main competitor, Apache's DBCP, and a few other OSS offerings like C3PO. You get what you take, and you take what you can get. Some people preferred mine, and some people preferred others.
So its cool for a while - you get people interested in your project, and thats great. You do some bug fixes, you feel good - you feel like you're part of the community. Jetbrains gave me an OSS IntelliJ license because I was OSS. Cool - part of the solution, not the problem.
But after a few years, you get a bit bored - most developer's I've met do.
I wound download my OSS a few months ago (well, say wound down - I just switched off the site - bad I know). But why did I do it ?
There were a couple of reasons -
1) To me, no-one ever seemed to contribute. I used to get a few "here's a bugfix" emails, and that was cool - and I appreciated them wholeheartedly - but on the whole I was contacted by hundreds of people over the years that would seem angry that "x" wasn't implemented or "y" had fricked over their site.
Now I worked hard to fix the critical bugs - I remember even taking a day off as holiday from my work position to fix a particularly bad bug (no - I wasn't supported by my workplace to work on the project, even though they were using it in their key systems).
After 8 years, 3 bug fixes from external sources makes you think "this is all take, no give".
2) I got better at coding. I started to get ashamed of the lack of unit tests, and shoddy coding. I wanted to retire it because I no longer respected the code.
3) DBCP caught up ! Its now, I believe, better (in the main sense that its better supported and no longer barfs under load (they had threading issues)).
4) I've moved on from Java ... I no longer see Java as a relevant language.
I've had a few emails since saying "where's it gone ?" and I've given them the source code ... but to be honest, I don't think my little project would be missed.
Which brings me on from the navel gazing to the real point ... I've been using a lot of not-well-known OSS lately, and I'm not really chuffed about the quality of it (which was one of the main reasons I got out of my own OSS offering).
I get that its great that you're giving out to the community - I did it too - but in 2011, is it OK to ship OSS software that isn't tested ? I'm going to go with no.
A lot of these guys are just people out there trying to give to the community, and I do respect it. It just feels there is no-where to when they don't know. Or when they get bored, like I did.
How do we (as a community) write quality OSS when the demand is small (but probably important to those using it) ?
Maybe there's an answer out there, maybe not.
I pushed some software OSS because, at the time (and this was back in 2002), I felt the best competitors at the time were buggy, and feature poor. I thought people would benefit from my software, and I think some people did.
I had some big people using it at some point - Xerox and Maersk were the biggest I think.
But mostly, it was fairly small companies, just looking to solve a problem they had, like me.
I wrote a Java connection pool - it was going against the main competitor, Apache's DBCP, and a few other OSS offerings like C3PO. You get what you take, and you take what you can get. Some people preferred mine, and some people preferred others.
So its cool for a while - you get people interested in your project, and thats great. You do some bug fixes, you feel good - you feel like you're part of the community. Jetbrains gave me an OSS IntelliJ license because I was OSS. Cool - part of the solution, not the problem.
But after a few years, you get a bit bored - most developer's I've met do.
I wound download my OSS a few months ago (well, say wound down - I just switched off the site - bad I know). But why did I do it ?
There were a couple of reasons -
1) To me, no-one ever seemed to contribute. I used to get a few "here's a bugfix" emails, and that was cool - and I appreciated them wholeheartedly - but on the whole I was contacted by hundreds of people over the years that would seem angry that "x" wasn't implemented or "y" had fricked over their site.
Now I worked hard to fix the critical bugs - I remember even taking a day off as holiday from my work position to fix a particularly bad bug (no - I wasn't supported by my workplace to work on the project, even though they were using it in their key systems).
After 8 years, 3 bug fixes from external sources makes you think "this is all take, no give".
2) I got better at coding. I started to get ashamed of the lack of unit tests, and shoddy coding. I wanted to retire it because I no longer respected the code.
3) DBCP caught up ! Its now, I believe, better (in the main sense that its better supported and no longer barfs under load (they had threading issues)).
4) I've moved on from Java ... I no longer see Java as a relevant language.
I've had a few emails since saying "where's it gone ?" and I've given them the source code ... but to be honest, I don't think my little project would be missed.
Which brings me on from the navel gazing to the real point ... I've been using a lot of not-well-known OSS lately, and I'm not really chuffed about the quality of it (which was one of the main reasons I got out of my own OSS offering).
I get that its great that you're giving out to the community - I did it too - but in 2011, is it OK to ship OSS software that isn't tested ? I'm going to go with no.
A lot of these guys are just people out there trying to give to the community, and I do respect it. It just feels there is no-where to when they don't know. Or when they get bored, like I did.
How do we (as a community) write quality OSS when the demand is small (but probably important to those using it) ?
Maybe there's an answer out there, maybe not.
Subscribe to:
Posts (Atom)