Why is the Java date API (java.util.Date, .Calendar) such a mess? -
as people painfully aware of now, java api handling calendar dates (specifically classes java.util.date
, java.util.calendar
) terrible mess.
off top of head:
- date mutable
- date represents timestamp, not date
- no easy way convert between date components (day, month, year...) , date
- calendar clunky use, , tries combine different calendar systems 1 class
this post sums quite well, , jsr-310 expains these problems.
now question is:
how did these classes make java sdk? of these problems seem obvious (especially date being mutable) , should have been easy avoid. how did happen? time pressure? or problems obvious in retrospect only?
i realize not strictly programming question, i'd find interesting understand how api design go wrong. after all, mistakes learning opportunity (and i'm curious).
someone put better ever it:
- class
date
represents specific instant in time, millisecond precision. design of class bad joke - sobering example of how programmers screw up. of methods in date deprecated, replaced methods in classes below.class
calendar
abstract class converting betweendate
object , set of integer fields such year, month, day, , hour.class
gregoriancalendar
subclass ofcalendar
in jdk. date-to-fields conversions calendar system in common use. sun licensed overengineered junk taligent - sobering example of how average programmers screw up.
from java programmers faq, version 07.x.1998, peter van der linden - part removed later versions though.
as mutability, lot of jdk classes suffer (point
, rectangle
, dimension
, ...). misdirected optimizations, i've heard say.
the idea want able reuse objects (o.getposition().x += 5
) rather creating copies (o.setposition(o.getposition().add(5, 0))
) have immutables. may have been idea vms, while it's isn't modern vms.
Comments
Post a Comment