r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

Show parent comments

2

u/llogiq Feb 22 '15

I usually whip up a quick unit test + debugger if I need to test something, but I also sometimes just start a beanshell.

2

u/yogthos Feb 22 '15

Sure, but that's still more work than simply being able to look at a function and know what it's doing definitely. The other big aspect of it is the REPL, which provides far more fluid integration than the debugger or the beanshell. As you can see here the editor is linked up with the running image of the app and you can evaluate any function you write directly in the context of the application.

1

u/llogiq Feb 23 '15

It may be a bit more work (although given a good IDE, it's but a few keystrokes), but on the plus side, I get a unit test. :-)

1

u/yogthos Feb 23 '15

I get unit tests in Clojure as well, I just don't need nearly as many since the code is stateless. Also recommend looking at this. With Clojure, I can trivially mock any function in a test without having the code being mocked to be designed with that in mind.

For example, let's say there's a function, and it doesn't even have to be in my own code, could be a function from a library I'm using.

(defn get-user [connection id]
  (jdbc/query connection ["select * from users where id = ?" id]))

Now I'm doing unit tests and I want to have a mock user instead of checking the database:

(testing "get-user"
  (with-redefs [get-user (fn [_ _] {:id "bob" :pass "fake"})]
    (is (= {:id "bob" :pass "fake"} (get-user)))))

It's like monkey patching, but safe and locally scoped.

1

u/llogiq Feb 23 '15

I don't care much about mocking. During my time in consulting in an enterprise development scenario, I had to use it on occasion, but it was neither sufficiently awesome nor sufficiently painful to leave much of an impression.

1

u/yogthos Feb 23 '15

Mocking is just an example of how with-redefs can be useful.