Nilenso Software LLP, #105, 10th Cross, Indiranagar Stage 1, Bangalore, India, 560038
A few days into learning clojure, I thought it would be a good idea to look at some actual clojure projects in github. I was feeling all confident and what not – you know getting used to lispy way of writing things. The purpose of going through some code, was to get a gist of what was going on in the code, if not understanding it fully. I guess you already know where this is going don’t you ? Yep, I find myself reading through code and I find these two,
->> (and a lot more scary stuff) staring at me, and I had no clue what to make of it. I guess there would at least be a few of you guys who felt the same.
Apparently, they are called threading macros.
-> is the thread first and
->> thread last macros, and they are syntactical sugar to your code. It makes reading/writing code easier. “Meh! Just that?” you ask. Let’s see.
Let say you want to do this (divide 2 by 1 then subtract 3 then add 4 and multiply with 5). How would you write it in clojure?
Boy! It can get difficult to read when you have a bunch of these strung together.
Now lets see how we write it with
Woh! This is a lot simpler to read (at least for me)! So what happens here is the thread first macro just takes the 2 and then pass it as the first argument to the next function and then the result of that as the first argument to the next and so on.
Thread last does something similar, instead of passing it as the first argument it would pass it as the last argument. So if you where to apply the
->> to the previous example you would get
My favourite use of the threading macros has been when I have used them with java/clojure data structures. It makes handling them a lot easier.
The thread-last macro
->> is very useful in dealing with collections. Where you have to transform them or apply functions to them, which is what you might be doing in a lot of your clojure code. For example, if you have this collection:
Say you want to add a new ‘\n’ at the end of each line and then print them together as a single string. How would you do this? Well its easy, you just get the text and then apply map and reduce to it and then print. Let’s write it shall we?
Now lets take a look at this if we decide to write it using thread last macro
It’s a lot more cleaner, and you don’t have to keep matching the parenthesis to actually figure out what is happening. This works even better when you want to do a lot more transformation on the collections.
While at it, we can make use of this neat function
get-in that helps you get values from deep inside a map, which is somewhat better to use at times. The advantage of using
get-in over the threading would be that it helps you supply a
not-found value, the would be returned if the key you are looking for is not there in the collection. Pretty neat huh? Let’s try that.
Now if you are working with java interop and you aren’t using the thread-first macro, then this might change your mind. Let’s take this example, where you have a java object and you apply a series of methods on the Java object or Java objects returned on applying these methods. This is how you would be doing it.
Now with thread first this becomes
Which is way more easier to read, and write. It is aligned with the original java representation, which aids in better understanding of the code. It feels less clunky than the previous case where you could get lost in all those parenthesis.
Since we are at it, let’s talk about another function:
doto. This is very helpful when you have to apply multiple functions on a single java object. We didn’t use it in the previous example because, each of the functions were returning a different object.
Consider you have a table-border object and you want to set border to it. This is how you would be writing with thread the
You could use the threading operator or even write it in a single line, but it would be messy.
A threading macro can be used to reverse the read order: the value is primarily for people reading your code later; if using a threading macro doesn’t feel like it will make your code easier for the next person to read, it’s probably the wrong choice.
If everything that goes into a good conference happens invisibly, it's hard to know how to run a conference of your own. In the free/open-source spirit, I hope the folks from FOSSMeet (and other conferences) start documenting their procedures, contact points, processes, and materials.
How did you find speakers? Who did you reach out to for content and sponsorship? How did you make the website? How did you coordinate organization? How did you arrange the conference with faculty? What were some of the pitfalls the next organizers should watch out for?
Even if this "document" is little more than a blog post with an appropriate title, it could really help someone in the future. Preferably, organizers could publish a living document under a free/open license so other people can iterate on it. I've had multiple conversation with the HasGeek folks about documenting and publishing their procedures.
I always ask people why they are FOSS proponents and what their desired outcomes are. Answers vary wildly, but building a community (or maintaining one) is often high on everyone's list. Every Indian metropolis is facing a garbage crisis at the moment and events organized and attended by educated, privileged individuals should be setting the standard for city living. I was pleased to see chai served in paper cups at FOSSMeet but disappointed to see food served with styrofoam plates and plastic spoons.
Students at NIT Calicut (and other respected universities) may not even be aware that their privilege puts them in the spotlight. When they move to a city like Bangalore or Mumbai, they are the instantly the new educated middle-class of that city. Their behaviour influences others in profound ways and their preferences shape the economy. Demonstrating and advocating for Zero Waste in public spaces like University-hosted conferences is a fantastic way to raise awareness.
Zero Waste events are entirely possible and the resources exist to learn how to run one. Check out 2bin1bag.in, write to them with questions at email@example.com, and download their Zero Waste Event resources.
It's not necessary to go completely paperless -- I was happy to have my paper schedule crumpled in my pocket as I jumped from one workshop to the next talk. But a single A4 printed schedule is probably plenty.
"Have nothing in your house that you do not know to be useful, or believe to be beautiful." -William MorrisI would take this suggestion from Morris one step further: having nothing that you do not know to be useful and believe to be beautiful. Dr. Sasi Kumar mentioned this in his opening keynote: why give a bouquet of flowers? Why not a single flower? Why not a book?
At FOSSMeet, we received plaques thanking us for our time and participation. This is a wonderful gesture and I do feel the plaque falls into the "beautiful" category. However, now that I'm back in Bangalore, it will do little but engage its own beauty on the bookshelf of the nilenso library. If I had been given a book, I would have ample opportunity to think back to my weekend at FOSSMeet and to share that with others. I can hardly imagine a gift I would rather receive than a book, for any occasion.
Reach Out to Reach Out
Most of FOSSMeet was orchestrated through the NIT Calicut alumni network, which I think is fantastic. This approach could be taken one step further: Have the network reach out to their networks, as much as possible. A conference on Free and Open Source Software is bound to have a wide appeal, since there is likely to be little or no marketing for joining such-and-such company or buying into such-and-such product.
Free and Open Source Software (as far as this conference was concerned, at least) is in use in every corporation, in every office, and in almost every role. Often the network of FOSS, open data, open networks, and free documentation is non-obvious. This means that a conference focused on FOSS is likely to succeed by reaching out to more companies, non-profits, and user groups. At worst, you'll be ignored. But it's very likely you will find a whole new branch of free and open society you didn't even know existed.
The networks in the post-university world are vast... but surprisingly tight. Make a point of using social media to engage with potential speakers and attendees months in advance. Not everyone will make it to FOSSMeet 2017 but hopefully we will all know about it.
For FOSSMeet, it would have been nice to see heavier use of the @fossmeet twitter handle. Usually events like this have photos and quotes coming out of such a handle left-right-and-centre. That Twitter account can also be a triage for other communication, as it's easy for people to reach out with a quick tweet before they are pointed toward the correct IRC channel, mailing list, email address, or phone number. The 8 contact points at the bottom of the fossmeet.in website are a bit daunting. If I weren't sure how to travel to NIT Calicut (or any other university) or what my residential arrangements would be, my first preference would be to tweet or email a central contact point.
These are all minor feedback points, but I hope that everyone running conferences at least takes a serious look at the first three (Document, Zero Waste, and Beautiful Things) as these could quickly create a feedback loop fostering increasingly positive events, year on year.