testing

Testing tools, testing philosophy & methodology...
seancorfield 2017-09-13T00:04:50.000150Z

BTW, regarding that PDF, Copey is known for all sorts of heretical counter-opinions too (I remember back in the early days of design patterns and a lot of the OOP conferences of the mid-90's, you'd often find him in the audience heckling speakers on a variety of topics 🙂 )

seancorfield 2017-09-13T00:05:06.000166Z

This rebuts a lot of Copey's arguments https://henrikwarne.com/2014/09/04/a-response-to-why-most-unit-testing-is-waste/

seancorfield 2017-09-13T00:12:44.000212Z

Also note that most of the problems both DHH and Copey bring up are specific to OOP...

seancorfield 2017-09-13T06:10:19.000099Z

A fascinating piece -- much appreciated!! And, bottom line, I think we're in broad agreement: write simple code, use tests to ensure 1. it does the right thing and 2. it doesn't break when we refactor it.... yes?

seancorfield 2017-09-13T06:10:56.000088Z

So, really, the only contention is whether "test-first" actually drives design

seancorfield 2017-09-13T06:10:57.000126Z

?

2017-09-13T06:12:40.000028Z

Yup. Actually, I believe test first does drive design. I just don't think its the only way to write well designed code. And sometimes, its can be over designed for tests, hurting a bit.

2017-09-13T06:12:53.000027Z

And, I'm bad at writing the test first

seancorfield 2017-09-13T06:14:14.000041Z

There's no One True Way(tm)...

2017-09-13T06:17:59.000227Z

Definitely not

vuuvi 2017-09-13T19:27:45.000191Z

@john would it wrong to manually make a file in the test?

john 2017-09-13T19:29:51.000641Z

That's what I was thinking... I did not give the correct advice on how to do so though.

john 2017-09-13T19:30:16.000102Z

If StringReader is working for you, you should probably use that.

2017-09-13T19:30:25.000434Z

usually File is too specific a type to work with - eg. it doesn’t transition to code that uses a URL or a resource inside a jar

2017-09-13T19:30:29.000441Z

which are common things to want

2017-09-13T19:30:58.000369Z

if you write the code in terms of InputStream or Reader, you can just pass it some source of data and not worry about those details

vuuvi 2017-09-13T19:31:11.000425Z

.readline is doing a fine job of skipping ahead in the csv

2017-09-13T19:31:23.000264Z

right, but you can .readline on things that aren’t Files

vuuvi 2017-09-13T19:31:41.000371Z

oh I didn’t know that

2017-09-13T19:33:28.000198Z

it’s a method on BufferedReader, which you can make from pretty much anything you would get input from (string, url, file, resource inside jar, …)

2017-09-13T19:34:05.000310Z

also, in clojure, it’s convenient to use line-seq since you can then use our nice sequence abstractions

john 2017-09-13T19:34:41.000352Z

(def text-with-spaces-reader
  (java.io.BufferedReader.
    (java.io.StringReader.
" some csv text here ")))

john 2017-09-13T19:36:18.000631Z

(with-open [rdr text-with-spaces-reader] (drop 2 (line-seq rdr)))

vuuvi 2017-09-13T19:36:24.000732Z

but I’d still need to change my function inside the core.clj file in order to get the test to work right?

john 2017-09-13T19:36:53.000023Z

might not have to

john 2017-09-13T19:37:24.000393Z

if the thing just wants a .readLineable thing

2017-09-13T19:37:53.000116Z

peregrine.circle=&gt; (<http://clojure.java.io/reader|clojure.java.io/reader> (java.io.StringReader. "foo\nbar\nbaz"))
#object[java.io.BufferedReader 0x1a1ca2cd "java.io.BufferedReader@1a1ca2cd"]
peregrine.circle=&gt; (line-seq *1)
("foo" "bar" "baz")

2017-09-13T19:38:15.000516Z

http://clojure.java.io/reader is smart about creating BufferedReader

vuuvi 2017-09-13T19:38:43.000031Z

I see

vuuvi 2017-09-13T19:39:25.000129Z

I am trying to use @john ‘s code to drop 2 since that’s a much better solution than my current one and I keep getting a ‘unable to resolve rdr in this context’ error

john 2017-09-13T19:40:29.000489Z

did you evaluate the text-with-spaces-reader def first?

vuuvi 2017-09-13T19:41:14.000061Z

no I am trying to update the function in my core first

vuuvi 2017-09-13T19:43:04.000054Z

because the reader has the with-open in it so I would like to get it working there before I try to figure out testing

john 2017-09-13T19:44:40.000270Z

what does your with-open for look like?

vuuvi 2017-09-13T19:45:36.000043Z

(with-open [rdr (io/reader file)]

john 2017-09-13T19:46:14.000026Z

hmmm. Not sure why you'd be getting that error then...

vuuvi 2017-09-13T19:46:52.000102Z

yeah

john 2017-09-13T19:47:07.000394Z

check your parenthesis and make sure rdr is in scope

vuuvi 2017-09-13T19:47:25.000191Z

and for some reason when I break it out into a seperate function I stop having the symbol error and I get a problem with “null pointer exception” meaning something in my data is wrong

john 2017-09-13T19:49:41.000176Z

really hard to tell, without seeing the code. I'm able to do a line-seq on a (io/reader file) over here.

vuuvi 2017-09-13T19:50:22.000095Z

yeah thanks so much for your help sorry I can’t be more communicative

vuuvi 2017-09-13T19:50:27.000618Z

Clojure is a whole new world for me

john 2017-09-13T19:51:15.000288Z

Learning the new idioms takes a minute, but it's worth it 🙂

vuuvi 2017-09-13T19:53:33.000340Z

it seems like it!

vuuvi 2017-09-13T19:54:20.000522Z

so here’s a thought - the rdr stream gets passed into a variety of other functions that parse the raw stream into a map

john 2017-09-13T19:55:25.000375Z

are you implementing your own csv parser?

vuuvi 2017-09-13T19:57:30.000451Z

nope I’m using the clojure csv

vuuvi 2017-09-13T19:57:47.000005Z

and then there is a function that is unique

vuuvi 2017-09-13T19:57:49.000500Z

it looks like

vuuvi 2017-09-13T19:57:50.000426Z

(let [raw-csv (csv/read-csv rdr)] (doall (csv-data->maps raw-csv)))))

john 2017-09-13T20:00:20.000283Z

I would make that its own top level function

john 2017-09-13T20:00:25.000635Z

for testing purposes

👍 1