News for hackers. Stuff that matters.
Re:Ask YC: Fewer lines of clever code or more lines of clear... by pmjordan on Sunday June 22, 2008 @05:36PM (#224439)
Your problem here is that you're mixing logic and presentation, so it's neither clever nor clear. I'm not 100% sure what you're trying to do (your explanation again mixes everything together making it hard to understand) but I think you want to do this:

- Transform the screen position to a week-based relative coordinate system.

- Convert that spatial coordinate into a time stamp represented as seconds since the epoch.

That's a minimum of two steps, two verbs and therefore two separate functions. Step 1 can be broken down further by introducing helper functions for inspecting the DOM, decoupling the representation of the UI elements from your actual screen-space coordinate system, as CSS isn't in a nicely-scriptable format.

Once you've done this, you'll discover the result to be only marginally longer, but highly reusable.

Re:Ask YC: Fewer lines of clever code or more lines of clear... by technoguyrob on Sunday June 22, 2008 @06:16PM (#224454)
Sorry for not being clear about that. The purpose of this helper method (hence the underline before that name) is to take an event positioned in the DOM and convert its position into a timestamp for that event. Probably the only place this will be called is when some change is made to the DOM of the event. For example, when it is resized, it'll have a different height as well as "top" offset, so that'll have to be translated into a timestamp. I don't know any other way to do this that would be fundamentally different, since at some point the pixel-based resizing is going to have to become a timestamp. Nothing in this function will be used anywhere else, hence I didn't make any more helper functions for my helper function. Thanks!

EDIT: And yes, I agree, if I ever decide to make events more fancy than just dropping in a DIV on the timetable, I'll probably have to do a bit more. But of course, only a couple things will change then, and I can just write those as helper functions for this function.

Re:Ask YC: Fewer lines of clever code or more lines of clear... by aaronblohowiak on Sunday June 22, 2008 @09:43PM (#224587)
A separation of concerns is not just good for flexibility, it also helps with debuggability and readability and is a reflection of ability.