Tag Archives: clojure

Event: Testing Business Logic using DSLs in Clojure – Mayank Jain of @HelpShift

TechJam presents a talk about testing business logic using DSLs, by Mayank Jain, of @Helpshift, on Thursday 16 July, at 6:30pm, at IDeaS.com, Baner Road.

Testing business logic quickly becomes tricky, as applications grow and scale. Example based unit and integration tests, and exploratory tests become poor choices to check and verify a large state space. Also such methods are not well-suited to clearly describe the state space / transitions we want to test.

Since we use Clojure to write test suites and tools at Helpshift, we tried experimenting with DSLs to express some of our testing problems. We’ve found that mini DSLs can indeed become useful to describe and test fairly complicated business logic.

In this talk I will cover some of the mini-DSL approaches we’ve tried, demonstrate one of them by example, and discuss the benefits and drawbacks based on current experience.

About TechJam

TechJam is a non-profit initiative to build a community of techies, who are interested in learning and exploring new technologies.

Fees and Registration

This event is free and open for anybody to attend. Please register here: http://techjam.org/#dsl_clojure

Please double-check the date/time/venue of the event at the above link. We try to ensure that PuneTech calendar listings are accurate, but occasional errors creep in.

Event Report of @GhoseB’s 2-Day Clojure workshop – by @SwaroopCH

Last weekend BG aka @ghoseb conducted a 2-day free Clojure workshop – which was “sold out” and many people had to be disappointed.

Swaroop C H (who is famous for many things, one of which is A Byte of Python a free online book that has helped many people learn Python), was apparently in town, and attended the two sessions.

He has written a detailed and insightful event report. Here is his report of day 1 and report of day 2.

BG has promised to conduct another workshop for the people who couldn’t be accommodated in the first one due to space constraints.

Free 2-Day Intensive Clojure Workshop – 24-25 Aug

the Pune Clojure User Group is organizing an intensive 2-day workshop on Clojure – on 24-25 August. The workshop is designed for programmers who have been using imperative programming languages so far and will give them a solid foundation in Functional Programming, Clojure & the Lisp-way.

The course is completely free of charge thanks to gracious hosts, BMC Software. Seats are limited, so hurry!

Course Content

  • Data Structures
  • Functional Programming
  • Sequences & Collections
  • JVM Interop
  • Concurrency
  • OO & Polymorphism
  • Macros
  • A lot more!

Prerequisites

You don’t need any prior experience with Clojure, Lisp or Functional Programming but we do expect that all participants will have at least an intermediate level of experience with any programming language. We can’t teach you programming in two days but if you already know some programming we can definitely teach you a different (and extremely elegant) way of solving non-trivial problems.

You’ll have to bring your own laptop to the course. WiFi will be provided at the venue.

It’s also recommended that you setup your favourite editor for editing Clojure so that we can get started very quickly. Some resources are given in the resources section and others can be found online.

If you still have questions feel free to ask on the Pune Clojure mailing list.

About the Instructor – Baishampayan Ghose

Baishampayan “BG” Ghose has been a professional Lisp programmer for most of his career. He has been using Clojure since the early days and has contributed to Clojure and multiple libraries in the Clojure ecosystem. His areas of interest are functional programming, distributed systems & ethnobotany.

Currently he is Co-founder/CTO at Helpshift.

You can contact him on @ghoseb or b.ghose@freegeek.in

Fees and Registration

The event is on 24-25 August, from 9:30am to 5pm, at BMC Software, SB Road, Pune.

This event is free and open for anybody to attend. Seats are limited, so please register here fast.

About the PuneTech Calendar

Get event announcements by email. Subscribe (free) to the PuneTech Calendar

LiveBlog #tw5: Intro to Functional Programming & Why it’s important

This is a live-blog of TechWeekend 5 on Functional Programming. Please keep checking regularly, this will be updated once every 15 minutes until 1pm.

Why Functional Programming Matters by Dhananjay Nene

Dhananjay Nene started off with an introductory talk on FP – what it is, and why it is important.

FP is a language in which functions have no side-effects. i.e., the result of a function is purely dependent on its inputs. There is no state maintained.

Effects/Implications of “no side effects”

  • Side-effects are necessary: FP doesn’t mean completely side-effect free. If you have no side-effects, you can’t do IO. So, FP really means “largely side-effect free”. Specifically, there are very few parts of the code that have side-effects, and you know exactly which those are.
  • Testability: Unit Testing becomes much easier. There are no “bizarre interactions” between different parts of the code. “Integration” testing becomes much easier, because there are no hidden effects.
  • Immutability: There are no “variables”. Once a value has been assigned to a ‘name’, that value is ‘final’. You can’t change the value of that ‘name’ since that would be ‘state’ and need ‘side-effects’ to change it.
  • Lazy Evaluation: Since a function always produces the same result, the compiler is free to decide when to execute the function. Thus, it might decide to not execute a function until that value is really needed. This gives rise to lazy evaluation.
  • Concurrency control is not so much of a problem. Concurrency control and locks are really needed because you’re afraid that your data might be modified by someone else while you’re accessing it. This issue disappears if your data is immutable.
  • Easier parallelization: The biggest problem with parallelizing programs is handling all the concurrency control issues correctly. This becomes a much smaller problem with FP.
  • Good for multi-core: As the world moves to multi-core architectures, more and more parallelism will be needed. And humans are terrible at writing parallel programs. FP can help, because FP programs are intrinsically, automatically parallelizable.

Another important feature of functional programming languages is the existence of higher order functions. Basically in FP, functions can be treated just like data structures. They can be passed in as parameters to other functions, and they can be returned as the results of functions. This makes much more powerful abstractions possible. (If you know dependency injection, then higher-order functions are dependency injection on steroids.)

FP gives brevity. Programs written in FP will typically be much shorter than comparable imperative programs. This is probably because of higher-order functions and clojures. Compare the size of the quicksort code in Haskell vs. Java at this page

You need to think differently when you start doing functional programming.

Think different:

  • Use recursion or comprehensions instead of loops
  • Use pattern matching instead of if conditions
  • Use pattern matching instead of state machines
  • Information transformation instead of sequence of tasks
  • Software Transactional Memory FTW!

Advantages of FP:

  • After initial ramp-up issues, development will be faster in FP
  • Code is shorter (easier to read, understand)
  • Clearer expression of intention of developer
  • Big ball of mud is harder to achieve with pure functions. You will not really see comments like “I don’t know why this piece of code works, but it works. Please don’t change it.”
  • Once you get used to FP, it is much more enjoyable.
  • Faster, better, cheaper and more enjoyable. What’s not to like?

The cost of doing FP:

  • Re-training the developers’ brains (this is a fixed cost). Because of having to think differently. Can’t just get this from books. Must do some FP programming.
  • You can suffer from a lack of third-party libraries(?), but if you pick a language like Clojure which sits on the JVM, then you can easily access java libraries for the things that don’t exist natively in your language.

Should a company do it’s next project in a functional programming language? Dhananjay’s recommendation: start with small projects, and check whether you have the organizational capacity for FP. Then move on to larger and larger projects. If you’re sure that you have good programmers, and there happens to be a 6-month project for which you’re OK if it actually becomes a 12-month project, then definitely do it in FP. BG’s correction (based on his own experience): the 6-month project will only become a 8-month project.

Some things to know about Erlang by Bhasker Kode

Bhasker is the CEO of http://hover.in. They use Erlang in production for their web service.

Erlang was created in 1986 by developers at Ericsson for their telecom stack. This was later open-sourced and is now a widely used language.

Erlang is made up of many “processes”. These are programming language constructs – not real operating system processes. But otherwise, they are similar to OS processes. Each process executes independently of other processes. Processes do not share any data. Only message passing is allowed between processes. There are a number of schedulers which schedule processes to run. Normally, you will have as many schedulers as you have cores on your machine. Erlang processes are very lightweight.

Garbage collection is very easy, because as soon as a process dies, all its private date can be garbage collected because this is not shared with anyone else.

Another interesting thing about Erlang is that the pattern matching (which is used in all functional programming languages) can actually match binary strings also. This makes it much easier to deal with binary data packets.

Erlang has inbuilt support and language features for handling failures of processors, and which process takes over the job and so on, supervisor processes, etc.

Erlang allows you to think beyond for loops. Create processes which sit around waiting for instructions from you. And then the primary paradigm of programming is to send a bunch of tasks to a bunch of processes in parallel, and wait for results to come back.

Some erlang applications for developers:

  • Webservers built in erlang: Yaws, mochiweb, nitrogen, misultin
  • Databases built in erlang: amazon simpledb, riak, couch, dynomite, hibari, scalaris
  • Testing frameworks: distil, eunit, quickcheck, tsung

Who is using erlang? Amazon (simpledb), Facebook (facebook chat), microsoft, github, nokia (disco crawler), ea (the games company), rabbitmq (a messaging application), ejabberd (the chat server, which has not crahsed in 10 years). Indian companies using erlang: geodesic, http://hover.in.

How Clojure handles the Expression Problem by Baishampayan Ghose

If you’ve gone deep into any programming language, you will find a reference to lisp somewhere. So, every programmer must be interested in lisp. To quote Eric Raymond:

LISP is worth learning for the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot.

BG had conducted a 2 day Clojure tutorial in Pune a few months back, and he will happily do that again if there is enough interest. This talk is not about the basics of Clojure. It is talking about a specific problem, and how it is solved in Clojure, in the hope that it gives some interesting insights into Clojure.

Clojure is a dialect of lisp. And the first thing that anybody notices about lisp is all the parantheses. Don’t be afraid of the parantheses. After a few days of coding in lisp, you will stop noticing them.

Clojure has:

  • first-class regular expressions. A # followed by a string is a regular expression.
  • arbitrary precision integers and doubles. So don’t worry about the data-type of your numbers. (It internally uses the appropriately sized data types.)
  • code as data and data as code. Clojure (and lisp) is homoiconic. So lisp code is just lists, and hence can be manipulated in the program by your program to create new program constructs. This is the most ‘difficult’ and most powerful part of all lisp based languages. Google for “macros in lisp” to learn more. Most people don’t “get” this for a long time, and when they “get” lisp macros, the suddenly become very productive in lisp.
  • has a nice way to attach metadata to functions. For example, type hints attached to functions can help improve performance
  • possibility of speed. With proper type-hints, Clojure can be as fast as Java

_(Sorry: had to leave the talk early because of some other commitments. Will try to update this article later (in a day or two) based on inputs from other people.)

Clojure, Erlang, & Functional Programming – Intro to FP & Why It’s Important – TechWeekend5 18 Dec

Have you heard of Clojure, Erlang, Scala, F# and wondered why people are getting all excited about these new fangled languages? Then this is your chance to find out. And if you are a programmer or are otherwise working in the software technology space and have not heard any of those names, then you need to start reading more, and you certainly need to attend this TechWeekend5 in Pune this Saturday. Register for the event here.

Vayana Services and TechWeekend Pune presents a detailed session on Functional Programming this Saturday, 18th December from 10am to 1pm, at Sumant Moolgaonkar Auditorium, MCCIA in ICC Trade Tower (A Wing, Ground floor), S.B. Road. You must attend.

Object-Oriented Programming is now passe, and all the cool kids (i.e. the star programmers) have started looking very seriously at functional programming languages like Clojure and Erlang. The more visionary ones (like our speakers this week: Dhananjay Nene, Bhasker Kode, and Baishampayan Ghose) are building the next generation of products in these languages.

Find out the What, the Why and the How on Saturday.

There will be three talks, listed below, and some time for general discussions around this topic.

Why you should care about functional programming – by Dhananjay Nene

This talk will focus on important characteristics of functional programming and the current landscape in terms of variety of languages and its adoption. The talk will also refer to how leveraging it can help you in terms of brevity, concurrency, better abstractions, testability, economics and particularly enjoyability. A small part of the talk will also focus very superficially on the Scala programming language.

About the Speaker – Dhananjay Nene

Dhananjay is a passionate programmer and a consulting software architect. He loves to learn, research, prototype and deploy new technologies and languages even as he is strongly focused on ensuring that the choices are made consistent with the business objectives and landscape. He currently writes code for and advises Vayana Enterprises in his role as its Chief Architect.

An Introduction to Erlang – by Bhasker Kode

While ideating hover.in towards the end of 2007 Bhasker soon become an ardent evangelist of Erlang and it’s fault tolerant nature traditionally intended for use in telecom & messaging circles. Following it’s rising use in building real-time and low-latency applications at web scale Bhasker has presented Hover’s erlang growth stories at Commercial Users of Functional Programming Conference in Edinburgh along with Facebook, Erlang Factory in London, and Foss.in in Bangalore talking about the role of functional programming. Hover’s engineering efforts can be tracked at http://developers.hover.in

About the Speaker – Bhasker Kode

Bhasker is the CEO and Co-Founder of Pune-based Hover Technologies, a user-engagement platform that allows web publishers to add a new channel of earning ad revenue through the use of in-text “tooltip” based ads. He has always been captured by the potential of the internet as part of the core team behind several destination portals and startups from his college days in Chennai. His introduction to functional programming came from his stint as the first few developers at Bangalore based Tutorvista where he built the calendar, syndication, whiteboard among other products used by thousands across the world everyday.

Clojure & its solution to the Expression Problem – Baishampayan Ghose

The “Expression Problem” arises when we want to add new functionality to a library that we don’t control. Most popular programming languages accomplish this task by Monkey Patching, Wrapper Classes, etc. In this talk, BG will discuss the demerits of traditional approaches to the problem and how Clojure solves this problem using Protocols. This talk is intended to show-off the real power of Clojure in solving complex problems.

BG has chosen to talk about a particular feature of Clojure in depth instead of skimming over many things in a hurry because he believes that Clojure’s approach to solving the Expression Problem clearly demonstrates the thought process that has gone into designing the language and shows how it’s different from most other programming languages. I will also cover the very basics of reading Clojure code in just a few minutes which will also demonstrate the simplicity of the language itself.

About the Speaker – Baishampayan Ghose

Baishampayan Ghose (mostly known as BG) is the co-founder & CTO of http://Paisa.com. He has been a career Functional Programmer and has programmed professionally in Common Lisp, Clojure & now Erlang.

About the Sponsor – Vayana Services

Vayana Services offers an easier option for small and medium enterprises to obtain working capital financing from banks by electronically sourcing, transferring and tracking digitally signed trade documents across trading parties and banks. It is a financial service backed by a cloud based offering with its development and operations management team based in Pune. With a strong belief that healthy businesses are greatly assisted by using healthy technology, Vayana Services looks forward to an increasingly frequent and high quality interaction within the software technology community in Pune and welcomes you all to Techweekend 5.

Logistics

This event is free for all to attend, but please register here. The event is in MCCIA’s Sumant Moolgaokar Auditorium, ICC Towers, Wing A, Ground Floor. From 10am-1pm. The hashtag for the event is #tw5