Spurious Logic

« Older Posts  —  Newer Posts »

crunchcrunchcrunch

Well, it’s not quite 80 hour work weeks but a project is getting near code complete for the first release so between that additional pressure and parenting time at home and trying to buy a house there’s been no time for posts.

Hopefully I will be back posting weekly by the end of the month, but probably not before that.

Yes, it is yet another why I’m not posting post.

ka-Pow!!!

Take that! unnecessary table variable! Removed by the power of common table expressions!

I have a table in the form:

ID Seller Description
1 Alice widget1
2 Alice widget2
3 Bob widget1
4 Bob widget3
5 Bob widget4

But what I really need is a table with an extra column with a sales id for each seller, like this;

ID Seller Sales Id Description
1 Alice 1 widget1
2 Alice 2 widget2
3 Bob 1 widget1
4 Bob 2 widget3
5 Bob 3 widget4

In a past life I would have written the alter script to add in the column, with an empty field (null or -1); created a temporary table to iterate over every ‘Alice’ sale and set those values, followed by those for ‘Bob’. And this is what you get when you’re thinking procedurally. Using Common Table Expressions and a Partition makes this far more efficient (at the cost of more complicated code).

WITH cte (ID, seller, sales_id)
AS
   (
      SELECT
         ID,
         seller,
         ROW_NUMBER() OVER (PARTITION BY ID ORDER BY ID)
      FROM sales WITH (NOLOCK)
   )
UPDATE S
SET S.sales_id = C.Pattern_ID
FROM sales S
INNER JOIN cte C
   ON S.ID = C.ID
AND S.seller = C.seller

And hey! a legitimate reason to actually use a <table> on a webpage without designers shaking their goate-ed heads at my foolishness.

Mental Block

Following on from my gearshift analogy yesterday, my personal programming mental block is the syntax of the switch statement. I know how it works, I know what it does, I just can’t get the syntax right without looking it up. Regardless of the programming language. Java, C# or TSQL. I get as far as CASE … before I have to research it. It’s a pain in the ass but I just can’t get it to stick and I don’t use it often enough to memorise it properly. Ah well.

Just for reference, in TSQL this is what you want to be doing:

SELECT
   CASE tab1.col_name
      WHEN 1 THEN 'one'
      WHEN 2 THEN 'two'
END
FROM table1 tab1

Yes it’s trivial, but it just won’t stick. Maybe it will now.

mental gearshift

And this is what happens if you’re doing SQL and then get shunted up into procedural code and then back down again.

In C#:

  • you have variable names like local_Variable_Name instead of localVariableName.
  • The fact that you can call methods without prefixing the name with EXEC seems… just, wrong.

In TSQL

  • you keep on forgetting to use SET before variable assignment.
  • the fundamental set based versus procedural programming approaches which means that fast running procedures become very, very slow when you get them wrong.

oy vey. The trials of a generalist.

<meta> Having great big images and cleverly formatted text is great for show and all but it does mean that I’m not posting as much as I’d like, so, I’m going to try and set up a separate Articles section for longer/better posts and have a the usual blog style on the front page. </meta>

image from wikimedia commons

How deep does the rabbit hole go?

I find myself slipping more and more into extreme geekery.

This week I’ve:

  1. started obsessing about getting myself a new mechanical pencil.
    Currently the front runners are a straight replacement of what I currently have or this. I’m thinking that the MUJI pencil is more practical, cheaper and I prefer it’s clean design. I’ve had my current one for around 2 years at the moment and it’s been perfect for notes and sketches
  2. got really excited about a project here at work dealing with translating arbitrary input strings out into four distinct columns using a set of user defined rules. Taking a project from requirements all the way through design, feedback to implementation, testing and deployment is something I haven’t done in a while and it makes a very nice break from maintenance work.
  3. performed binary to digital conversion in my head for fun…

Image from : By John Tenniel (Alice in Wonderland) [Public domain], via Wikimedia Commons

New years resolution

Well, 3rd week of January resolution. I’m going to track my time and the task I work on in the office as accurately and honestly as I can.

Currently we’ve got a very rough cut timetable system where everyone fills in their time after the fact using very broad work categories. 99% of the time this works absolutely fine. Last week we had a request to give a total amount of time for a particular project. Of course no-one on the team was tracking this one project distinct from the others so the best we could do was dead reckoning. It’s definitely wrong but it should at least be in the right ball park.

A co-worker turned me on to Grindstone which is a fine granularity recording mechanism for windows. You set up tasks, hit the start button and away you go. At the end of the day/week you can get a bunch of nice reports on the time you spent on the different task.

The only difficult bit is to be honest with it. That time you spend on youtube? You’ll be tempted to mark it as “working on defect” but you’re only tricking yourself.

I would hesitate to recommend it for project managers to enforce it on your employees because it rely’s entirely on the honesty of your staff (which shouldn’t really be a problem) but more than that, it gives the developers a very big brother feeling. It’s not enjoyable working if there’s no wiggle room and if developers can’t even pretend they enjoy their jobs, then they won’t be very productive.

Image is taken from commons.wikimedia.org (resized and resampled)

Put on your geek hat

I imagine I’m not the only person who got vaguely excited that today is a purely binary date 11.01.11 (or 01.11.11 if you use a broken datetime format) or 55 in decimal. It was very satisfying to spend an idle moment converting from binary 110111 to decimal 55 (or 011111 to 31). Just reminds me of all the low level stuff I learned back in college which I will almost never use (and if I am actually using as part of my job, then something has gone very, very wrong – hardware engineers excepted).

image from zazzle.com

Things I have learned…

… or confessions of a newborn’s father.

So this is a purely personal opinion based on my experiences. Your birth experience will be different. You’ll have different priorities, make different choices all under different circumstances. We were lucky enough to have a fantastic midwife locally and chose to go for a home birth. Birthing was tough but without complications and really, it all went fantastically well. Of course this has coloured my opinions so you’ll have to take that into account when you’re reading this. (more…)

« Newer Posts  —  Older Posts »