This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!

Gary Deer

+ Follow
since Aug 20, 2010
Gary likes ...
Android Clojure Ubuntu
My life in haiku
Born Raised Nothing else to say
I'm an open book
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gary Deer

I just wanted to add a practical example in case this post shows up in a Google search for when-let

Lets say you have a function that takes a map.
If the passed in map has the key :username you want to do something with it. Otherwise you can return nil or do something else
If you want to return nil then use when-let if you want to do something else use if-let

Exercise for the reader:
1) if the map has the :username key return a greeting with the name, otherwise return a generic greeting
2) same as 1 except return nil if missing

These forms prevent repetition to make your code look cleaner.

Exercise 3: refactor this code
`(when (:count state-map) (let [count (:count state-map)] (str "count is :" count)))`
4 years ago
I saw this video

And now I'm experimenting with actually doing this. I'll let yall know how it goes.
8 years ago
I've run into a few delays while trying to do this side project since I had to prepare for my java certification exam (which I passed) and do a lot of other non-programming tasks. So after four months I'm just now getting back into it. I've learned quite a bit of Clojure in the mean time and I've started thinking in more of a functional way.

I'm really leaning toward using a database example for my presentation. Some of the pain points with databases are messy queries, verbose prepared statements, and object-relational impedance mismatch.

On my github account I've started a Clojure project that uses and sqlKorma . I'll be adding to it over the course of next week. Since I'm using an Oracle database I'll post the tkprof output to show the performance.

9 years ago

Sean Corfield wrote:I haven't seen any benchmarks - and I think the performance improvements will be very dependent on which language features you use heavily... I'm not sure they're across the board changes...

oh, I meant specifically in what you were doing. I'd like to say, though, that I'm not one of those people that focuses on trivial benchmark improvements on specific cases; I just thought it would be interesting to see an example.

9 years ago
I like the improved error messages. There was quite a bit of grumbling on the mailing list about cryptic error messages. I never minded that so much because it was usually an issue with an expression I was working with at the time. But being able do something like (fn x) without any warning when you create it and a cryptic messages when you try to use it could be a pain.

Do you have any benchmarks to post? Would like to see the performance improvements.

Now when are they going to abandon the decimal system and just start calling it Clojure 5 , 6, 7, etc?

9 years ago

Jk Robbins wrote:

I'm not even clear on the differences between functional, imperative, and procedural programming, so it seems like a good place to start.

I've started on the Python tutorials but I'd like to hear some opinions.

What's the best way to learn functional programming? What are your favorite websites or books? Is Python a good choice or should I start with something else like Haskell or Scala?

btw, I have no experience with calculus, so I realize that I need to start with an understanding of lambda calculus. Pointers on this are welcome.

The differences between functional, imperative and procedural programming:
Imperative: writing statements that change state.
example: start here,set x, do this to x, then that, get a file, write from file onto x, error if no file, x += "I'm a mutant", print x, done.
Procedural: imperative with subroutines. If state changes are localized or tied to a procedures then it's structured programming.
example: start here,set x, x.doThis(), x.thenThat(), x += openFile("mutants.txt").readLine().toString(), closeFile() , printf(x), return 0
Functional: avoid state and mutable data which means that functions don't have side effects (1 + 1 will always be 2 or rather x + y will always be the sum of x and y)

How closely the language adheres to that determines its purity. Haskell is pure; Clojure and Scala are not. I personally like how Clojure handles state and mutable objects which is why I've chosen to learn it.

Python has lambdas and you could definitely do FP in Python, but it would only be by convention. Since Python doesn't force you to think in a functional way, it might not be the best language for learning FP. That was also the reason I didn't choose Scala to learn FP, I wasn't having to think differently about my problems. Using Clojure has started to transform the way I approach problems.

Keep in mind these are just my own personal opinions, individual results may vary.
Wow that is a lot nicer than the automated gui regression testing framework I'm having to deal with at the moment. Thanks for sharing.

I really like how I was able to show your code snippets to someone who had never seen Clojure before and they were still able to explain what is going on in the "edit-my-profile" test in a matter of seconds -- quite a beautiful thing.

Is Browser-based testing one of those boring things you use Clojure for, or is this the start of a new series on doing the interesting things in Clojure?

9 years ago

chris webster wrote:Yes, I've been visiting InfoQ again (it's like daytime television for nerds), and this time I found an interesting informal talk (1 hour) about how Clojure was introduced to replace key components of a complex Java-based system at an investment bank:

There's a lot of discussion about the cultural/political aspects of doing this in a relatively conservative organisation, as well as the technical challenges.

Hakan talked a bit fast at times which when coupled with his accent and sentence structure made it a bit difficult to understand on first listen. I wonder if what really happened is that Hakan suggested using Clojure and people just nodded and agreed without understanding what he was saying until finally Jon had a meeting with the team to show them what they all agreed to. By that time it was too late and everyone was too embarrassed to admit they were just being polite. That's using people's political correctness against them. Okay, I'm done with my infoQ fanfiction.

You could tell the people asking questions during Q & A were a bit disappointed that there was no simple answer to the biggest hurdles they had. Their story seemed to have a lot of elements of luck as well. I like how everyone went and learned Clojure over the Xmas break when there is a freeze in production because that's kind of how I finally got a chance to delve into the language.

I can't believe they got people using emacs as well. That would be a deal breaker at most shops (by most I mean most of the shops I've worked in, not all shops in the world.)

It did give me food for thought as to what kinds of problems to use Clojure for. Yes, it is a general purpose language but you do have to take into consideration a lot of context. Clojure is good for a wide range of problems if your team is using it and everyone is comfortable with it. But if you're trying to get your first professional Clojure project going it has to be one that is worth the extra effort and demonstrates the power of Clojure. I'm still searching for that golden opportunity in my own organization. Once I find it and I can get the productivity fiends and the tech fashionistas interested, that will be the turning point.

I hope to see more videos like this in the future.
9 years ago

chris webster wrote:

Gary Deer wrote:I can play around with Clojure when I'm ... on the toilette.

My apologies. I'll make sure I edit that part out of my post when the "edit" button comes back.

Back on topic, I forgot to mention the ClojureTv channel on youtube. It has a lot of good videos from all the big conferences like No Fluff Just Stuff, StrangeLoop, etc.

9 years ago
Yes, got this to work, thanks.

Using gen-class takes some getting used to, but once I had a working example to play with I started to get it.

I'll try to build off of this and post any interesting discoveries. I'm also going to work on some sort of automation for the build, should be a short shell script.

Thanks for your help.
9 years ago
I have a small Java program that I'm trying to rewrite in Clojure little by little. The first piece I wanted to convert was my logging. I used log4j and I saw a blog post about writing logging in Clojure with log4j, but I didn't see anything about using that for logging in the Java code.

But before I did all that I wanted to see if I could write a simple Clojure file that had functions I could call from a Java program. It was not as easy as I thought it would be. First there were the form considerations (gen-class deftype, defrecord, etc.) then the namespace issues, then aot fun, and after all that, the java classes won't compile. I also tried using leiningen which only made it worse somehow.

With Java interoperability there is a lot to consider. Like if I were to use gen-class for parts to maintain interop with Java parts and then I rewrite those parts in Clojure, will I then need to go back and rewrite the whole thing removing all the interop mess?

I'm in a weird position of trying to create a practical example from a trivial program. But, when I tell people that Clojure has great interoperability with Java, I would like to show them an example of Clojure calling Java and Java Calling Clojure in harmony. Even better if I could give someone a jar that is Clojure files packaged by leiningen that they can use without even knowing it was all written in Clojure.

I'm hoping that the more I play around with it, the more it will click, but as of right now I feel like I'm shaving a yak.
9 years ago

Alisa Peter wrote:Linux is the best Operating System

This makes me sad inside.

This is why...

I know it's common place to blur the line between the kernel and the OS, but as the neckbeardhacker says:
The developer who wrote just 1% of Linux Kernel code gets 99% of the credit. #OccupyLinus

As far as the distros go, creating niche distros is kind of a sport in the neckbeard underground so keeping up with them all is harder than memorizing the names of all of the US Presidents and their extended family.

9 years ago
Start with Ubuntu, it's easy to install which will give you an immediate environment to get in and "root" around.

As far as learning Gnu/Linux, you need to know how to get around, install things, and read man pages.
Getting around includes things like command line file system navigation (ls, cd -, cd ~, grep, etc.)
Installing things is as easy as "apt-get install" and there's also a nice tool called "aptitude" for searching and downloading things
Reading man pages is as simple as typing "man <thing>" you can even read "man pages" on the command to read man pages
If you're not sure what to read man pages on, just type "ls usr/bin" and start reading man pages on things that look interesting

Since the output of that might be too big to fit in the prompt there's an easy solution that you'll use a lot...pipe it.
"ls /usr/bin | less" will pipe the results of the ls into less which lets you scroll through the text. Read the man pages for more details.

In windows if you ever used the "type" keyword from command line, you'll be using "cat" And you can also pipe that into less or you can just call less on the file.

another thing I tend to do a lot is pipe results into grep. Like, "ls ~/Documents | grep java" prints all the files in my documents folder that contain the word java

of course multiple pipes are possible "cat war_and_peace.txt | grep peace | less" pipes every line of my text file that contains the word peace into less

Once you're familiar doing those basic things you can continue to accrete your command line wizadry.

Lastly, if you haven't already done so, find all the linux jokes on xkcd...start with this one
9 years ago
I'm sure I'll be a bit more active now that I've had time to start diving in. I've almost finished the Clojure book I won during the promo and I'm starting to get the hang of the Koans and problems.

9 years ago
I've actually volunteered for a collateral project to explore the benefits of the "up and coming JVM languages." It was meant to be just an academic paper that I would post on the company confluence site for everyone to ignore, but I've actually started to enjoy Clojure so it will probably end up being more. From all the papers I've read, videos I've watched, and the chapter from the book (thanks to the Book Promo contest I won), I've found quite a lot of selling points for Clojure. Not only just in and of itself, but also compared to any other technology that we could adopt.

There are some hurdles to overcome like a paradigm shift from over-used OOP to FP and the fact that it does have totally different syntax that seems a bit daunting at first. Still, if I can prove out all of the good points that I've seen I'll have a great case.

I saw Paul deGrandis's talk on Clojure-powered startups and he said that Clojure manages risk better than any other technology. That's definitely an underlying theme that would be good to have.

It will be interesting to see how my strategy works. I know "sneaking Clojure past the boss" is just tongue-in-cheek, but I'd like to think my boss is more open to good ideas so i can take a more head-on tactic.
9 years ago