Fork me on GitHub
#off-topic
<
2016-04-27
>
thebeatcoder08:04:12

Guys, I have one non-related to Clojure question. Should a programmer add unit tests for private methods?

thebeatcoder08:04:28

If this method was extracted from bigger public one only for readability anf consistency

conormcd08:04:37

I test private functions if they're complex. I don't test all private functions.

sickill09:04:54

If you feel a need to test a private function/method then this may be an indicator of some abstraction missing

thiagofm11:04:37

@thebeatcoder: you can just test the abstraction for the cases that private function covers

thebeatcoder11:04:19

@thiagofm do you mean test it indirectly by covering public methods using that private one?

thebeatcoder11:04:39

I follow the same principles but I'm debating w/ my colleagues abot that

thiagofm11:04:41

@thebeatcoder: your private function should do something. Add a number, log something, write something to a file, anything. You can write a test case that given that you ran the public function, you got the behavior expected from that specific private function, or that your public function gives the right results(so the private fn has to be working).

thiagofm11:04:44

@thebeatcoder: there's plenty of discussions regarding that on google which have way more words than I could provide to you. There's no absolute truth of course.

thebeatcoder11:04:27

@thiagofm definitely, I just want to get different points of view for this question. Thank you!

thebeatcoder11:04:57

As for me, direct testing of private methods is like "refactoring hell" because any structural changes that should be changed on first-class member redound on fixing existing unit tests, writing others with similar assertions etc. And, of course, nobody will want to do any refactorings on the existing codebase in such case.

telent12:04:19

I suggest that a workable middle ground might often be "test private functions if they're complex but you (and colleagues) have carte blanche to delete the tests if/when you make changes that mean they start failing"

telent12:04:24

sometimes it's helpful to write tests to drive the current implementation, sometimes the tests you write are useful records of the specification, but not every test always can perform both roles

bojan.matic12:04:00

I finally got my dead tree copy of SICP! Now, I figure I need a scheme implemenation to follow, what would you guys recommend? Can racket fit the bill?

thiagofm12:04:51

@bojan.matic: I think you can do it nicely with racket, perhaps you might have a thing that is different or two, but adapting for those should be straightforward

bojan.matic12:04:19

can I get a scheme that would require 0 adapting?

bojan.matic12:04:33

or is there no more such a thing?

thiagofm12:04:54

@bojan.matic: gambit scheme perhaps?

thiagofm13:04:47

But I wouldn't worry about that detail. I think the whole book is way more about problems/reasoning than a specific programming language.

thiagofm13:04:13

I advise you do all the exercises. Don't skip any of them.

thiagofm13:04:24

Also run all the examples

bojan.matic13:04:25

i just thought it might be easier to not bog myself down in language details

thiagofm13:04:08

I'm sure this is the smallest detail in any case you would do for this book.

thiagofm13:04:21

Also follow the video lectures from MIT

bojan.matic13:04:31

oh, video lectures?

bojan.matic13:04:35

first time hearing it

thiagofm13:04:20

They are kind of old, but all applicable today, and of course, are based in the content of the book.

karlis15:04:03

How often do these happen (the last one was in January 2016)? I'd love to participate in the next one.

plexus17:04:39

@karlis: no idea ,I only found out about it today