Fork me on GitHub
#testing
<
2017-09-13
>
seancorfield00:09:50

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 🙂 )

seancorfield00:09:44

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

seancorfield06:09:19

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?

seancorfield06:09:56

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

didibus06:09:40

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.

didibus06:09:53

And, I'm bad at writing the test first

seancorfield06:09:14

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

didibus06:09:59

Definitely not

vuuvi19:09:45

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

john19:09:51

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

john19:09:16

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

noisesmith19:09:25

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

noisesmith19:09:29

which are common things to want

noisesmith19:09:58

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

vuuvi19:09:11

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

noisesmith19:09:23

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

vuuvi19:09:41

oh I didn’t know that

noisesmith19:09:28

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, …)

noisesmith19:09:05

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

john19:09:41

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

john19:09:18

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

vuuvi19:09:24

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

john19:09:53

might not have to

john19:09:24

if the thing just wants a .readLineable thing

noisesmith19:09:53

peregrine.circle=> ( (java.io.StringReader. "foo\nbar\nbaz"))
#object[java.io.BufferedReader 0x1a1ca2cd "java.io.BufferedReader@1a1ca2cd"]
peregrine.circle=> (line-seq *1)
("foo" "bar" "baz")

noisesmith19:09:15

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

vuuvi19:09:25

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

john19:09:29

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

vuuvi19:09:14

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

vuuvi19:09:04

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

john19:09:40

what does your with-open for look like?

vuuvi19:09:36

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

john19:09:14

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

john19:09:07

check your parenthesis and make sure rdr is in scope

vuuvi19:09:25

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

john19:09:41

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

vuuvi19:09:22

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

vuuvi19:09:27

Clojure is a whole new world for me

john19:09:15

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

vuuvi19:09:33

it seems like it!

vuuvi19:09:20

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

john19:09:25

are you implementing your own csv parser?

vuuvi19:09:30

nope I’m using the clojure csv

vuuvi19:09:47

and then there is a function that is unique

vuuvi19:09:49

it looks like

vuuvi19:09:50

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

john20:09:20

I would make that its own top level function

john20:09:25

for testing purposes