baavgai: (Default)
( Jan. 11th, 2007 10:10 pm)
The examples of computer code you find on the Internet are a mixed bag. Some are well done, even inspired. Most are imbued with whatever quirks were harbored by their creator. Much is so fabulously bad that it's had to imagine it runs. But, like anything, even bad examples have something to teach.

I used to think the vast amount of open source available for casual perusal was probably a reasonable sampling of how people code. I now think I'm being optimistic. Every time I turn over a virtual rock and catch a glimpse of the inner workings of stuff my company has already paid for, it's invariably abysmal.

I now think that the really, really bad code is the stuff people are ashamed of showing and so call proprietary. I'd like to think I'm wrong and the inner workings of things I can't see might hold trade secret ensconced brilliance, but I'm just pretty sure that's not the case.

I could offer a few real world examples, but I'm currently trying to fix those and enumerating them would only lead to my despair. The stupid hurts. So, to be mollified by the pain of others, I go here instead. It's almost soothing.
baavgai: (Default)
( Jan. 3rd, 2007 12:23 pm)
Most systems reckon time as a function of the date and the time. All databases I know of do this. Even those that say they have a different type for date and time just usually just hide the other half.

Oracle's method of storage is kind of neat. It's a big number that's the number of days since the year 1700. The time is a fraction. So, to get just a date, Oracle has this:

select trunc(sysdate) from dual

If you don't know this, there is an ugly hack that takes advantage of character conversions to cut off the time, it looks like this:

select to_date(to_char(sysdate,'YYYYMMDD'),'YYYYMMDD') from dual

Micrsofts SQL Server doubtless has a similar mechanism somewhere. However, the equivalent of Oracle's trunc(sysdate) doesn't seem available. There are many methods out there, all kind of cludgy. That character conversion hack for Oracle I noted? Well, that kind of method is the best I've found for SQL Server. And here is is:

SELECT CONVERT(datetime, CONVERT(varchar(10), GetDate(), 101))

Please, if anyone finds a better one, let me know.


baavgai: (Default)



RSS Atom

Most Popular Tags

Powered by Dreamwidth Studios

Style Credit

Expand Cut Tags

No cut tags