Friday, 29 March 2013

Building a Paradox

According to Wikipedia[1]:
“A paradox is an argument that produces an inconsistency, typically within logic or common sense.”
Every once in a while, it helps to do something that is totally unrelated to the field of Software Design. In my case I like to make the occasional wooden thing. In this case, I decided to build a wooden paradox.

Just to elaborate, I wished to make a wooden version of Curry's Paradox[2]. If you wish to know how the trick works, youtube[3] has some very good explanations.

This little project is one of the easiest I've made. (Quickest too)

Ingredients

  • some wood, 1 cm thickness, made of glued-together-layers of wood
  • different colour paints
  • varnish
  • magnets

Utensils:
  • a fretsaw (I used an iron saw, because I'm short a fretsaw)
  • glue
  • sandpaper
  • tapemeasure (essential)
  • pencil
  • paper (I used cm2 paper)
  • scissors
  • eraser
  • brushes

The Making Of


Cut the shapes out of paper.

Mark the shapes on the wood.

Saw the shapes using the fretsaw.
Use sandpaper on the pieces.

Paint them.

Varnish them.

After drying, apply glue to the magnets and glue them to the shapes.

Done.

It's not rocket science!

Notes

I managed to make something appropriate using an iron saw instead of a fretsaw, and I do not recommend it. It's a pain to create 90 degrees corners.

Next time need to sandpaper more, as the edges were quite rough.

References

[1] Paradox - Wikipedia
http://en.wikipedia.org/wiki/Paradox
[2] Missing square puzzle
http://en.wikipedia.org/wiki/Missing_square_puzzle
[3] Curry's Paradox and the Notion of Area: Part I (Tanton)
http://youtu.be/eFw0878Ig-A

Curry's Paradox


Friday, 15 March 2013

Natural Progression of Java for Statement

Introduction


I find it fascinating the way Java is being developed, and accrues different new features from other "newer" programming languages.

One of the things that struck me forcefully recently, is the progression of our beloved for Statement. So forcefully, that I had to make a blog about it.

Output of the programs listed below is always:
James Gosling is 57 years old.
Charles Babbage is 221 years old.
Alan Turing is 100 years old.
Donald Knuth is 75 years old.
Edsger Dijkstra is 82 years old.
Anyone interested in the Person.java class used, can find it here.

Version 1

This is the way we did it back in the old days. A counter for 0 until we reached the size of the list we wanted to iterate over. And every time we had to cast what we got out of the list, as the list contained Objects.

Version 2

Finally! A Collections framework! With default naming, so we could always more or less assume what the exact Contract was that the Collection adhered to, once we knew the name of the Collection used.

Version 2.5

Yay! No more casting, no more 'counters' and we can add a variable number of arguments to some of our collection framework methods.

Version 7

Small change, due to project Coin. We have a simpler notation for Generics.

Version 8

Lambdas, here we come!

Conclusion

The for-loop, while still a very important tool in the arsenal of the Developer, seems to have been relegated to the internals of the Frameworks. I would not be surprised if the for-loop will become used less and less.

Small note

Whilst trying to get Lambda functions to work, I made the mistake to download the OpenJDK snapshot from Oracle that does not actually contain Lambda syntax yet. Try [1].

References

The for Statement
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
Maurice Naftalin's Lambda FAQ
http://www.lambdafaq.org/
JDK 8 Features
http://openjdk.java.net/projects/jdk8/features
Java 8: The First Taste of Lambdas
http://zeroturnaround.com/labs/java-8-the-first-taste-of-lambdas/
[1] Java™ Platform, Standard Edition 8 Early Access with Lambda Support
http://jdk8.java.net/lambda/
Java Version History
http://tech-my-talk.blogspot.in/2013/03/java-version-history.html