CodeSOD: Lucee Execution


I Love Lucy title

Recently, at my dayjob, I had a burning need to understand how scheduled tasks work. You see, we’ve recently switched from Adobe Coldfusion to Lucee, and I was shaky on how Adobe did things before, so I wanted a deeper understanding of how the code I was working on would be executed. For the uninitiated, Lucee is an open-source reimplementation of Cold Fusion. And that’s not the WTF.

It’s open source, I thought to myself. I’ll just take a look at the code.

I had one problem. Then I looked at the code. Now I have two problems … and a headache:


private long calculateNextExecution(long now, boolean notNow) {
	long nowTime=util.getMilliSecondsInDay(timeZone,now);
	long nowDate=now-nowTime;
		
		
	// when second or date intervall switch to current date
	if(startDate<nowDate && (cIntervall==Calendar.SECOND || cIntervall==Calendar.DATE))
		startDate=nowDate;
		
	// init calendar
	Calendar calendar = JREDateTimeUtil.getThreadCalendar(timeZone);
	calendar.setTimeInMillis(startDate+startTime);
		
	long time;
	while(true) {
		time=getMilliSecondsInDay(calendar);
		if(now<=calendar.getTimeInMillis() && time>=startTime) {
			// this is used because when cames back sometme to early
			if(notNow && (calendar.getTimeInMillis()-now)<1000);
			else if(intervall==ScheduleTaskImpl.INTERVAL_EVEREY && time>endTime)
				now=nowDate+DAY;
			else 
				break;
		}
		calendar.add(cIntervall, amount);
	}
	return calendar.getTimeInMillis();
}

"So okay, if now is before or starting at—hang on, what’s calendar again?" I found myself muttering aloud. "Okay, if now is before or equal to the start date plus the start time, and time—which, if I understand that method correctly, is the elapsed time in the current day—is after or equal to the start time … when is that true exactly? You know what would be nice? Some #%#@$%@ Javadoc!"

This is only one representative method, and yet, there’s just so much here. Why an if statement that does nothing, terminating in an easily-overlooked semicolon? Why the misspelling of EVERY? Or "Intervall?" Why are the programmers allergic to spaces? Why can’t they name variables worth anything? Do I even really want to know how this works anymore?

If you want to witness the madness for yourself, may I remind you: this code is open source. Have at ye. According to the copyright statement at the top, this code was inherited from the Railo project, so if you’re in Switzerland, please be sure to send your hate mail to the right address.


[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!

http://ift.tt/2qb6X7o

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s