Skip to main content

After deleting a web server, I started checking what I typed before hitting 'Enter'

3 months 2 weeks ago
Student thought she had the hang of this 'Linux' thing and its kooky CLI

Who, Me?  It's Monday morning, and a week of possibilities presents itself to IT pros everywhere. Which is why The Register brings you another edition of Who, Me? It's the reader-contributed column in which we remind you what not to do with your day, your week, and your career, by sharing stories of your worst workplace mistakes and the contortions you made to survive them.…

Simon Sharwood

CodeSOD: Functionally, a Date

3 months 2 weeks ago

Dates are messy things, full of complicated edge cases and surprising ways for our assumptions to fail. They lack the pure mathematical beauty of other data types, like integers. But that absence doesn't mean we can't apply the beautiful, concise, and simple tools of functional programming to handling dates.

I mean, you or I could. J Banana's co-worker seems to struggle a bit with it.

/** * compare two dates, rounding them to the day */ private static int compareDates( LocalDateTime date1, LocalDateTime date2 ) { List<BiFunction<LocalDateTime,LocalDateTime,Integer>> criterias = Arrays.asList( (d1,d2) -> d1.getYear() - d2.getYear(), (d1,d2) -> d1.getMonthValue() - d2.getMonthValue(), (d1,d2) -> d1.getDayOfMonth() - d2.getDayOfMonth() ); return criterias.stream() .map( f -> f.apply(date1, date2) ) .filter( r -> r != 0 ) .findFirst() .orElse( 0 ); }

This Java code creates a list containing three Java functions. Each function will take two dates and returns an integer. It then streams that list, applying each function in turn to a pair of dates. It then filters through the list of resulting integers for the first non-zero value, and failing that, returns just zero.

Why three functions? Well, because we have to check the year, the month, and the day. Obviously. The goal here is to return a negative value if date1 preceeds date2, zero if they're equal, and positive if date1 is later. And on this metric… it does work. That it works is what makes me hate it, honestly. This not only shouldn't work, but it should make the compiler so angry that the computer gets up and walks away until you've thought about what you've done.

Our submitter replaced all of this with a simple:

return date1.toLocalDate().compareTo( date2.toLocalDate() ); .comment { border; none; } [Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.
Remy Porter

A New Nuclear Rocket Concept Could Slash Mars Travel Time in Half

3 months 2 weeks ago
"Engineers from Ohio State University are developing a new way to power rocket engines," reports Gizmodo, "using liquid uranium for a faster, more efficient form of nuclear propulsion that could deliver round trips to Mars within a single year..." Nuclear propulsion uses a nuclear reactor to heat a liquid propellant to extremely high temperatures, turning it into a gas that's expelled through a nozzle and used to generate thrust. The newly developed engine concept, called the centrifugal nuclear thermal rocket (CNTR), uses liquid uranium to heat rocket propellant directly. In doing so, the engine promises more efficiency than traditional chemical rockets, as well as other nuclear propulsion engines, according to new research published in Acta Astronautica... Traditional chemical engines produce about 450 seconds of thrust from a given amount of propellant, a measure known as specific impulse. Nuclear propulsion engines can reach around 900 seconds, with the CNTR possibly pushing that number even higher. "You could have a safe one-way trip to Mars in six months, for example, as opposed to doing the same mission in a year," Spencer Christian, a PhD student at Ohio State and leader of CNTR's prototype construction, said in a statement. CNTR promises faster routes, but it could also use different types of propellant, like ammonia, methane, hydrazine, or propane, that can be found in asteroids or other objects in space. "Some potential hurdles include ensuring that the methods used for startup, operation and shutdown avoid instabilities," according to the researchers' announcement, as well as "envisioning ways to minimize the loss of uranium fuel and accommodate potential engine failures." But "This team's CNTR concept is expected to reach design readiness within the next five years..."

Read more of this story at Slashdot.

EditorDavid