Reason 1: Mocking.
unittest.mock, Python’s mocking framework is so much more powerful than EasyMock, Mockito, or any other Java mock framework I’ve ever used. You can replace any method you like with essentially arbitrary code. No longer do you have to contort APIs with convoluted dependency injection just to mock out network connections or reproduce error conditions.
Instead you just identify a method by name and module within the scope of the test method. When that method is invoked, the actual code is replaced with the mock code. You can do this long after the class being mocked was written. Model classes do not need to participate in their own mocking. You can mock any method anywhere at any time, in your own code or in dependencies. No dependency injection required. You can even mock fields.
By contrast Java only lets you mock objects (not methods) and only when you have an available API to insert the mock in place of the real thing.
Reason 2: None
is its own type.
Read the rest of this entry »
This entry was posted
on Sunday, December 10th, 2023 at 2:02 pm and is filed under Java, Programming.
You can follow any responses to this entry through the Atom feed.
You can skip to the end and make a comment. Pinging is currently not allowed.
Happy 20th Birthday Java! Next year I’ll buy you a drink. InfoWorld has published some of my thoughts on the occasion, “Java at 20: How it changed programming forever”.
This entry was posted
on Thursday, May 21st, 2015 at 6:21 am and is filed under Java.
You can follow any responses to this entry through the Atom feed.
You can skip to the end and make a comment. Pinging is currently not allowed.
java.util.Arrays
uses quicksort (actually dual pivot quicksort in the most recent version) for primitive types such as int
and mergesort for objects that implement Comparable
or use a Comparator
. Why the difference? Why not pick one and use it for all cases? Robert Sedgewick suggests that “the designer’s assessment of the idea that if a programmer’s using objects maybe space is not a critically important consideration and so the extra space used by mergesort maybe’s not a problem and if the programmer’s using primitive types maybe performance is the most important thing so we use the quicksort”, but I think there’s a much more obvious reason.
Read the rest of this entry »
This entry was posted
on Saturday, March 30th, 2013 at 6:51 am and is filed under Java.
You can follow any responses to this entry through the Atom feed.
Both comments and pings are currently closed.
In my day job I work with a lot of very smart developers who graduated from top university CS programs such as MIT, CMU, and Chicago. They cut their teeth on languages like Haskell, Scheme, and Lisp. They find functional programming to be a natural, intuitive, beautiful, and efficient style of programming. They’re only wrong about one of those.
Read the rest of this entry »
This entry was posted
on Sunday, January 20th, 2013 at 6:47 am and is filed under Java.
You can follow any responses to this entry through the Atom feed.
Both comments and pings are currently closed.
I hate 1% problems. No this isn’t an OWS slogan. I’m thinking of those code issues that really aren’t a problem 99% of the time, but when they bite, they’re really hard to debug and they cause real pain. Several common cases in Java:
- Using
java.util.Date
or java.util.Calendar
instead of JodaTime.
- Not specifying a
Locale
when doing language sensitive operations such as toLowerCase()
and toUpperCase()
.
- Not escaping strings passed to SQL, XML, HTML or other external formats.
What I hate most is that it’s really, really hard to convince other developers that these are problems they should take seriously.
Read the rest of this entry »
This entry was posted
on Sunday, July 22nd, 2012 at 10:58 am and is filed under Java, Programming.
You can follow any responses to this entry through the Atom feed.
You can make a comment or trackback from your own site.