Hacker News new | ask | show | jobs
by beders 2497 days ago
Extracting two columns out of a excel sheet:

     (->> (d/load-workbook file "Questionnaire.xlsx")
       (d/select-sheet "Sheet1")
       (d/select-columns {:A :item :B :price}))
2 comments

Now we're talking. It would probably take 20+ lines of C# to do the same thing.

How do you manage errors? What happens if Questionnaire.xlsx or Sheet1 doesn't exist ?

> How do you manage errors?

It becomes unwieldy like every other language.

> What happens if Questionnaire.xlsx or Sheet1 doesn't exist ?

Runtime exception.

I've seen too much Clojure code (and this goes for every language where error handling is optional - Hi Javascript!) just skip error handling and focus on "happy path".

And as demonised as Java's checked exceptions are, they at least forced error handling to be thought of.

Or you could use: https://github.com/adambard/failjure

Ya'll underestimate the power of a programming language to create a programming language. Just replace the arrow with `ok->>`

What is 'd'?
It's an alias given to an imported module name. In Python it might be:

  import really_long_name as rln
  rln.foo()
I know that part :) What module is it referencing?
I like the suggestion in namespace aliasing in https://stuartsierra.com/2015/05/10/clojure-namespace-aliase...:

As a general first rule, make the alias the same as the namespace name with the leading parts removed.

  (ns com.example.application
    (:require
     [clojure.java.io :as io]
     [clojure.string :as string]))
Keep enough trailing parts to make each alias unique. Did you know that namespace aliases can have dots in them?

  [clojure.data.xml :as data.xml]
  [clojure.xml :as xml]
Eliminate redundant words such as “core” and “clj” in aliases.

  [clj-http :as http]
  [clj-time.core :as time]
  [clj-time.format :as time.format]
Then you can see immediately what `d` is...

Namely:

  (require '[dk.ative.docjure.spreadsheet :as spreadsheet])
(You would still not know the library and might have to ask the same question, but it makes more sense.)

About `d`:

There are always exceptions. For example, some namespaces have established conventions for aliases:

  [datomic.api :as d]