Flutterby™! : Joy

Next unread comment / Catchup all unread comments User Account Info | Logout | XML/Pilot/etc versions | Long version (with comments) | Weblog archives | Site Map | | Browse Topics

Joy

2010-06-04 10:32:29.000069+00 by meuon 7 comments

Joy defined: When you coded some things sometime in 2005, in a way that were a pain but you thought it would pay off later. June 2010 (5 years later): Pay off, the code and thoughts worked well and saved me a LOT of time. PHP may not still be the darling of the web world, but it sure works well.

comments in descending chronological order (reverse):

#Comment Re: made: 2010-06-22 22:08:50.228235+00 by: meuon [edit history]

It doesn't have to be just code. It's an overall view of how things should be: data structures, logic and process flow. The front loading is is as much cognitive and lines of code.

In my most recent case (this week), it was a database structure, and a thought process and some PHP code in some other places done 3 years ago that made doing an arrears aging report (normally a real bitch) as easy as 10 straight simple SQL commands:

create temporary table zarage
select portal,account,arrearstype,arrearsid,datediff(now(),min(created)) as days, 
sum(amount) as balance from specialarrears 
group by portal,arrearstype,account,arrearsid order by days desc;
CREATE temporary TABLE `zar` ( `uniq` int(10) NOT NULL AUTO_INCREMENT,`account` varchar(20) DEFAULT '',
`arrearstype` varchar(80) DEFAULT '',`arrearsid` varchar(10) DEFAULT '',`0-30` double(16,2) NOT NULL default '0.00' ,
`30-60` double(16,2) NOT NULL default '0.00',`60-90` double(16,2) NOT NULL default '0.00',
`90-120` double(16,2) NOT NULL default '0.00',`120-150` double(16,2) NOT NULL default '0.00',
`150plus` double(16,2) NOT NULL default '0.00',`total` double(16,2) NOT NULL default '0.00',
PRIMARY KEY (`uniq`),UNIQUE KEY `id` (`uniq`),KEY `account` (`account`),KEY `arrearstype` (`arrearstype`),KEY `arrearsid` (`arrearsid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
insert into zar (arrearstype) select distinct(arrearstype) from arrearstype order by arrearstype ; 
update zar set `0-30` = (select sum(balance) from zarage where days >= 0 and days < 30 and arrearstype = zar.arrearstype) ;      
update zar set `30-60` = (select sum(balance) from zarage where days >= 30 and days < 60 and arrearstype = zar.arrearstype) ;    
update zar set `60-90` = (select sum(balance) from zarage where days >= 60 and days < 90 and arrearstype = zar.arrearstype) ;    
update zar set `90-120` = (select sum(balance) from zarage where days >= 90 and days < 120 and arrearstype = zar.arrearstype) ;  
update zar set `120-150` = (select sum(balance) from zarage where days >= 120 and days < 150 and arrearstype = zar.arrearstype) ;
update zar set `150plus` = (select sum(balance) from zarage where days >= 150 and arrearstype = zar.arrearstype) ;
update zar set `total` = (select sum(balance) from zarage where arrearstype = zar.arrearstype) ;
select * from zar ;

Was the core SQL. The guy from the "Oracle Financials Consultant" eyes rolled and told me that could not possibly be correct and work. He bought dinner. :) That I now type out such SQL and expect it to work blows my own mind. A sample of the final work from that code based is attached..

#Comment Re: made: 2010-06-22 21:43:04.544533+00 by: Dan Lyke

could just be selection bias... Front-loaded code that pays off is a good investment, front loaded code that doesn't is a load of overengineered crap. I don't think so, even though I'm having trouble articulating what the difference is, but I'll not claim to be immune to such effects.

#Comment Re: made: 2010-06-22 17:02:40.093744+00 by: Shawn

Dan; Hrm... "thought it would pay off later" still sounds like the latter to me.

#Comment Re: made: 2010-06-08 19:01:16.406515+00 by: Dan Lyke

Shawn, "(I am large, I contain multitudes.)".

But, actually, I think there are two types of this. The good type is of the form "I wrote that twice, I should turn that into an idiom", or "there are two instances of it, let's assume there'll be more". The bad type is "there's one instance, let's assume there'll be more".

#Comment Re: made: 2010-06-08 18:05:27.363507+00 by: Shawn

Wait a minute. Weren't you guys all part of a discussion awhile back that was asserting the idea that in the long term it doesn't make sense to take so much time designing for the future because you'll just wind up re-writing everything anyway?

(Although this is said in good-natured ribbing, I do recall such a discussion here, if not the specific players.)

#Comment Re: made: 2010-06-07 04:57:48.986673+00 by: brennen

I remember saying recently that probably the sweetest moment in a long-term commitment to programming is the one where you look at something you built a long time ago and realize that you got it right.

PHP, meanwhile, which I presently spend most of my workdays writing, is a disgusting and embarrassing mediocrity of a language, but I don't think I can reasonably deny that it works.

#Comment Re: made: 2010-06-04 22:16:17.717957+00 by: Dan Lyke

Yes, I love it when those little details pay off. Since I'm stuck in a big bunch of code where the pain wasn't taken up-front...