Fork me on GitHub
#clojure
<
2015-06-09
>
ul05:06:37

i have a weird question to community: how many columns considered to be a standard style for clojure source code width?

robert-stuttaford05:06:18

i think we’ve settled on 100, which is the widest that two panes of code can fit side by side on one of our engineer’s funny 1280x900 laptops

robert-stuttaford05:06:34

we all have an emacs thing that colours stuff beyond that point differently

jonas06:06:28

@ul I don’t think there’s a “community standard” for that

ul06:06:26

i guess we have no one, consider my question like a poll or something. i'm in doubts, so happy to hear numbers and reasoning, exactly in the same way @robert-stuttaford wrote (thanks!). I'm using 80 for a year, chosen it just to stick to smth. sane, but sometimes it seems too narrow, code becomes too much extended vertically, especially taking in account lisp-style argument alignment

escherize06:06:39

But I only follow that when it's convenient.

escherize06:06:57

otherwise i just turn off whitespace-mode (the emacs thing that highlights columns >80)

ul07:06:42

@escherize: thanks for the link, when i've read this guide last time it had no note about character limit

mikethompson07:06:45

There was a reason for 80 chars, back in the day when we thought vt100 terminals were cutting edge. But, surely, not any more. I'm absolutely a 100 char guy these days. That 80 char thing was a completely arbitrary limit forced by hardware and nothing to do with a good software reading/layout experience.

robert-stuttaford07:06:49

narrower columns make for nice side-by-side diffs or three-way diffs. helps!

cfleming07:06:18

I have mine set to 120 chars these days

cmdrdats08:06:44

I’ve found that 80 character width is just too narrow - 100 characters works well for me

pbalduino08:06:37

Sometimes a wider row can be a code smell, but a value between 100 and 120 is working well for the team.

ul09:06:28

does any shortcut already exist to extend protocol for several types with identical functions? like this:

(extend-protocol IProtocol
  AType
  BType
  (protocol-fn [_] "hello!"))
instead of
(extend-protocol IProtocol
  AType
  (protocol-fn [_] "hello!")
  BType
  (protocol-fn [_] "hello!"))

crisptrutski10:06:04

@ul Perhaps define your own simple extend-protocols macro? Don't think there's a shorthand in core

ul10:06:00

yes, that the path i will follow if no smth. standard. and i guess it actually doesn;t exist

ul10:06:15

@thheller: thanks, its a good base for a little hand-rolled macro doing the job

escherize10:06:55

How would I use test.check for functions that do CRUD on my db?

tjg10:06:14

I like to stick to 80, because my font (Monaco 14) and side-by-side Emacs windows wrap at 86 chars. But no biggie.

tjg10:06:57

(Already at Monaco 14, I wonder if others can comfortably see my text.)

martinklepsch10:06:49

it’s very narrow but still readable, ideal if you split windows a lot

tjg10:06:07

@martinklepsch: Ah cool, I'll check it out!

martinklepsch10:06:50

@delaguardo: that looks also interesting, thx

dnolen12:06:56

@ul 80 columns for me. I just disable Lisp argument alignment in all my editors. I find it unbearable. 2 space indent always except for data structure literals.

ul12:06:01

in what sense unbearable? hard to read quickly? too fast getting too wide?

dnolen12:06:54

@ul taste. I find it ugly and an impediment for reading.

escherize13:06:19

But I like hitting C-c n and having everything "where it should be"

escherize13:06:19

And I break lines if auto-format + current line-breaks look fugly

scttnlsn13:06:57

@dnolen: Is there an easy way to do that in Emacs or do you just redefine all these: https://github.com/clojure-emacs/clojure-mode/blob/master/clojure-mode.el#L798-L869

dnolen13:06:41

@scttnlsn: pretty sure clojure-mode has an option for this

scttnlsn13:06:58

@dnolen: Ahh, okay great. I’ll poke around. Thanks!

colin.yates14:06:54

@dnolen the day it is the indentation in my code that makes it ugly is the day I will be happy 😉

stephen14:06:24

Does anyone know Scala?

stephen14:06:50

I got this Scala method : def apply[T](clauses: (Double, Element[T])*) which I would like to call from Clojure.

stephen14:06:44

Reflecting on the method I see clauses is a scala.collection.Seq - but what is it a Seq of?

alandipert14:06:23

@steph: my guess would be Tuple2's

alandipert14:06:28

but i've been out of that game for quite awhile

stephen14:06:58

Ah yes of course.

stephen14:06:28

Thanks, looks to be the case.

minimal14:06:51

@stephen: i’ve used this a bit while trying do use sparkling https://github.com/t6/from-scala

stephen14:06:02

I have been using that library.

stephen14:06:07

It is invaluable!

minimal14:06:28

Looking at the code is useful

txus15:06:13

I love the component library

martinklepsch15:06:30

Wondering: (first (remove nil? (map (fn [x] (println x) x) [:tolo nil :test]))) in my understanding this should be lazy and only print :tolo — why isn’t it?

stig15:06:00

vectors are not lazy?

martinklepsch15:06:14

(first (remove nil? (map (fn [x] (println x) x) '(:tolo nil :test)))) works as expected

stig15:06:35

thought so simple_smile

martinklepsch15:06:41

I don’t really need it but now I’m wondering how I can turn a vector into a lazy seq, is that possible at all?

stig15:06:28

(seq [1 2 3])

martinklepsch15:06:07

If you run this: (first (remove nil? (map (fn [x] (println x) x) (seq [:tolo nil :test])))) it’s not lazy @stig

ghadi15:06:01

map is chunked.

ghadi15:06:18

look up "chunked sequences" (it's an optimization)

stig15:06:03

ghadi: that might be it. But why did the literal ‘(:tolo nil :test) work as expected then?

martinklepsch15:06:25

Maybe it’s the right time to go “one level up”: What I’m really trying to achieve is some short circuit like behaviour that returns the first non-nil result — not executing f on any remaining items

ghadi15:06:42

because vectors are chunked but lists aren't

ghadi15:06:14

martinklepsch: move your side effect to the outside

ghadi15:06:33

(let [item (first (remove ... coll))] (print item))

martinklepsch15:06:22

it’s not about the side effect, the function that returns nil or something (which I want) is expensive

alandipert15:06:41

the vector literal has it's own evaluation semantic

alandipert15:06:22

@martinklepsch: : e.g. it behaves like (vector 1 2 (doto 3 println)), evaluating its contents before returning itself

martinklepsch16:06:20

Thanks everyone, somehow I thought that if I use map it will just treat any passed list as lazy

mfikes17:06:24

@martinklepsch: Perhaps make use of reduced to terminate?

(reduce (fn [acc x] (println x) (if-not (nil? x) (reduced x))) nil [:tolo nil :test])

mfikes17:06:22

(You’d apply your f inside the nil? check, perhaps saving the value with an if-let or somesuch.)

mfikes17:06:15

@martinklepsch: (reduce (fn [acc x] (println x) (if-some [y (identity x)] (reduced y))) nil [:tolo nil :test]), replacing identity with your f?

alexmiller20:06:35

on the top-level thing, in some cases you could also wrap in a (do ) instead of splicing, although at that point you should probably question whether you should be using reader conditionals in the first place or just provide different namespace implementations specific to the platform

danielcompton20:06:42

@alexmiller: I thought I did describe that? > or use a do to wrap all of the top level functions:

danielcompton20:06:47

or do you mean somewhere else?

alexmiller20:06:55

I hadn't finished reading :)

alexmiller20:06:52

I think my pull request for the clojure-maven-plugin went in today to support cljc files :)

danielcompton21:06:50

@alexmiller: I was wondering about that. Will that support .cljc test files too?

chipf0rk21:06:39

I still don't get what `'~ does, is there any article or simple explanation about it

ul21:06:04

i guess it gives you quoted symbol inside macro

ul21:06:43

oh, wait, you are asking about `'~ in a row, or generally about quoting?

chipf0rk21:06:36

Specifically that combination

ul22:06:29

sometimes you want macro to put one of its arguments literally as it is typed in source code

ul22:06:38

this combination allows this, i'm not sure about correctness of my terms, but it is one of the ways to break macros' hygiene

ul22:06:22

something reverse to using x#

ul22:06:03

=> (defmacro f [x] `'~x) (f z)
z

mfikes23:06:49

@chipf0rk: Mastering Clojure Macros by Colin Jones covers `'~ in his Secret Macro Voodoo section, on page 25.