The long way through Software Craftsmanship

Iterate with index in clojure

Jul 4, 2015 - 2 minute read - Comments - sampleclojurerubyiteratelanguage-comparisonprotip

Scenario: iterate a sequence (seq) with its index

The lines have an implicit line number (starting by 1, in most editors):

[1] line1
[2] line2
[3] hello

When you read it from file to a variable, it is converted to:

("line1" "line2" "hello")

This implicit line number value is not present, therefore you need to assign them one.

In ruby, you have this construct:

array = ["A", "B", "C"]
array.each_with_index {|val, index| puts "#{val} => #{index}" }

Source

In clojure, there is a similar function:

(map-indexed (fn [idx itm] [idx itm]) '(:f :o))
; ([0 "line1"] [1 "line2"] [2 "hello"])

If you want to shift the collection to the right so it starts with 1 (for the REPL):

(def lines '("line1" "line2" "hello"))
; ("line1" "line2" "hello")

(defn shift-one [lines] 
  (cons "" lines))
(def lines (shift-one lines))
lines
; ("" "line1" "line2" "hello")

(map-indexed (fn [idx itm] [idx itm])
  lines)  
; ([0 ""] [1 "line1"] [2 "line2"] [3 "hello"])

Source, especially this one

But if you only need to get the lines at certain indexes, it is also possible to get the values directly, using map on the sequence of desired indexes:

lines
; ("" "line1" "line2" "hello")

(defn get-all [lines indexes]
  (map #(nth lines %) indexes))
(get-all lines '(1 2))
; ("line1" "line2")

(get-all lines '(1 1))
; ("line1" "line1")

Note: the original source code for this post is here

Brown-bag session: refactoring legacy code

Jul 1, 2015 - 1 minute read - Comments - refactoringlegacy-codetrainingbrown-bag-sessionclientlegacyslidespresentation

Today I have done a brown bag session about refactoring legacy code. It includes:

  • legacy code definition. There is no agreement about this in the team.
  • the legacy code change algorithm (source is Feathers, Working effectively with legacy code). Plus an example about it.
  • working with legacy code
  • experience with it.

The slides are available here (PDF format)

We also did a practical session, whose experience report is here

Self-study in July 2015

Jul 1, 2015 - 11 minute read - Comments - self-study-aggregationjuly2015rich-hickeyclojurejava-onepair-programmingcarlos-blerest-apijeff-knupppythonkris-jenkinsbackwards-compatibilityintegration-testjeremy-millerblack-box-testingwhite-box-testingedson-yanagadddjava-eevideorainsbergerintegrated-testintegration-testraul-rojaslambda-calculuspapersantiago-pinotdd-mistaketddmartin-fowlercouplingdesignmockmock-frameworkreadingself-studymeagan-wallerapprenticeship8th-lightpete-mcbreenchristopher-stracheyprogramming-languagetheory1967coursefundamental-conceptsreificationtype-erasureangelika-langerbjorn-tiplingintellij-ideapluginmisko-heverytestabilitytestable-codeclean-codementorrole-modeljoanne-wilsontype-theoryhashcodejavaralf-sternbergdvarianteric-normandfred-zemkesql-2011sqltracking-toolstakipisentryairbrakeraygunstackhunteralex-zhitnitskyblikip-vs-nptheoretical-computationelvira-mayordomodripstatjava-9unsafebackwards-compatibilityrob-austinnp-completelucia-mourayitz-schaffertpptransformation-priority-premisekatalinked-listbig-o-notationdata-structurebenchmarkattila-mihaly-balazsshortcutoleg-shelajevsummer-trainingpaymillxavi-hidalgooutsourcingvasco-duartedominic-krimmeragilepodcastoliver-whitelanguagecomparisonben-nadelbook-reviewrobert-c-martincraftsmanshipmonogamyanalogylocalstorageangularjszero-knowledgeclipperzdanijel-arsenovskic-sharpjava-agenttom-leightonmitocwopen-coursewarejulie-zelenskystanforddmitri-tikhanskijmeterheadless-testheadlessclojure-unraveledandrey-antukhalejandro-gomezradhika-ghosalalgosaurusbozhidar-bozhanovmark-hibberdstreamincremental-streamslidesmike-caulfieldfederationfederated-wikiandrew-montalentiparselyapache-kafkakafkapost-mortem-analysisalgorithmic-complexitybig-oh-notationrecursionclojurescriptmanuel-riveroproperty-based-testingquickchecktest-checkmanuel-chakravartywiptomas-rybingmike-cavalierecory-bergskillrockstarmichael-bernsteinprotocol-bufferprotobufferjsonjosh-szmajdatomasz-nurkiewiczeric-meyerconsidered-harmfulvenkat-subramaniamlambdacohesioncarin-meierjustin-weisspeter-provostkoanmichael-church

I’ve grouped all small posts related to the self-study from July 2015 into a single post

Clojure made simple

I’ve watched this talk by Rich Hickey at the Java One. It references the talk Easy made simple

  • polymorphism without inheritance; single dispatch on the first parameter

Productive pair programming

I’ve read this article about pair programming, using the driver & copilot technique, written by Carlos Blé

Building Automated REST APIs with Python

Investigating QA automation for REST APIs, I’ve read these slides about it

Backwards Compatibility Testing For Your Clojure Project

I’ve read this article on making leiningen test the application on several clojure versions. Written by Kris Jenkins.

Succeeding with Automated Integration Tests

I’ve read this article by Jeremy Miller on integration testing and how to succeed with it. Some notes:

  • Choose the Quickest, Useful Feedback Mechanism, even if that means testing the backend and frontend separately
  • Prefer white-box than black-box testing
  • Use quick tests, that can be run locally in an easy fashion
  • Do not share databases, as they introduce risks of flaky tests

Applied DDD in a Java EE 7 and Open Source World

I’ve watched this video by Edson Yanaga in the Java One, about DDD using Java EE 7, JSFs and lambdas on top of glassfish

Integrated tests are a scam

I’ve read, again, this article by J. B. Rainsberger on integrated tests and why not to use them. From a numerical / combinatorics point of view.

Functional Programming should be your #1 priority for 2015

I’ve read this introduction to functional programming by Ju Gonçalves. Explains some functional concepts, such as:

  • First-Class Functions
  • High-Order Functions
  • Pure Functions
  • Closures
  • Immutable State

Also recommends a few books on the subject (e.g., SICP, HTDP).

A Tutorial Introduction to the Lambda Calculus

I’ve read this paper, an introduction to the lambda calculus. Haven’t done the exercises. Written by Raúl Rojas

20 common mistakes when doing Test-Driven Development

I had thought of converting all of his tweets into a blog post, but he has already done this for us: I’ve read a list of common mistakes when doing TDD by Santiago Pino

Reducing coupling

I’ve read the article by Martin Fowler Reducing Coupling in the IEEE SOFTWARE July/August 2001

Comparing Java Mock Frameworks – Part 2: Creating Mock Objects

List of mock frameworks for java. Have only read the jMock, mockito and jMockit part.

## Software Craftsmanship book review

I’ve read this review for a book that is already pending in my book list: Software Craftsmanship by Pete McBreen.

The review has been written by Megan Waller, an (ex-)apprentice at 8th Light.

Fundamental concepts in programming languages

I’ve read this paper containing the contents for lectures in Computer Programming in the year 1967. Written by Christopher Strachey.

Note: I’ve also seen this paper recommended in the repo Papers We Love > plt (Programming Language Theory)

What is reification?

I’ve read this FAQ on reification by Angelika Langer

Type erasure

I’ve read this wikipedia page on type erasure

How to make an IntelliJ IDEA plugin in less than 30 minutes

I’ve read this article on creating new IntelliJ IDEA plugin, by Bjorn Tipling

How to Write Clean, Testable Code

I’ve watched, again, this video by Miško Hevery. Discusses what are the characteristics of tested and untested code, how to get from one to the other. Discusses techniques for testing code. At the end, there are questions but they cannot be heard (lack of microphone), so it is harder to follow.

How to Find a Mentor

I’ve read this opinion on the importance of role models and mentors. The difference between them and a personal experience. Written by Joanne Wilson

Type theory

I’ve read this wiki page on type theory

Some notes:

  • “type systems […] language feature used to reduce bugs”
  • two types: Church’s typed λ-calculi and Martin-Löf’s intuitionistic type theory.
  • notation:
    • typing judgement: M : A. Term M has type A
    • example: nat may be a type
    • 2 : nat, like in Scala
    • function: “arrow”
    • apply function to argument: no parenthesis
  • conversion rule: rule for rewriting terms
    • reduction rule: conversion rule that only works in one direction
  • normal form: a form that cannot be further reduced
  • element: all closed elements that can be reduced to the same normal form
  • closed term: a term without parameters. Opposite is an open term
  • convertibility: property of terms, both open and closed. Said to be convertible if two terms can be reduced to the same term
    • warning: x + 1 and 1 + x are not convertible because they are in normal form and not the same

Type system

I’ve read this wiki page on type system

Some notes:

  • “The depth of type constraints and the manner of their evaluation affect the typing of the language”
  • Type polymorphism
  • {compile time, runtime} x {manually annotated, inferred}
  • “A program associates each value with at least one particular type, but it also can occur that one value is associated with many subtypes.”
  • Classification of types:
    • data type – a type of a value
    • class – a type of an object
    • kind – a type of a type, or metatype
  • the type inference might be undecidable (for more complex type inference)
  • “Strong typing offers more safety, but cannot guarantee complete type safety.” An example is the division by zero, altough some languages may declare a dependent type “non-zero numbers”

The 3 things you should know about hashCode()

I’ve read this article on the hashCode() method in java, written by Ralf Sternberg.

Reduce Complexity with Variants

I’ve read this article on variants in clojure by Eric Normand

What is new in SQL:2011

I’ve read this white paper on the new features in SQL 2011. Written by Fred Zemke

5 Error Tracking Tools Java Developers Should Know

I’ve read this article about tracking tools for java written by Alex Zhitnitsky, featuring:

  • Raygun
  • Sentry
  • Takipi
  • Airbrake
  • StackHunter
  • [Bonus] ABRT
  • Comments cite Squash (server written in ruby, java client available) and Rollbar (home says supports android but not says anything about java)

Data clump

I’ve read this article on the bliki, by Martin Fowler

NP-Complete problems

I’ve read these slides by Prof. Elvira Mayordomo about NP-Complete problems, how to reduce them to other problems and practical applications. (In Spanish)

Removal of sun.misc.Unsafe in Java 9 - A disaster in the making

I’ve read this article about the removal of this Unsafe class in Java 9, by the DripStat team

How To Write Directly to a Memory Locations In Java

I’ve read this guide on how to write directly to a memory position in java, by Rob Austin

Interesting uses of sun.misc.Unsafe

I’ve read this article by Haris A.L.

Introduction to the theory of np-completeness

I’ve read these notes / slides to the introductory course of NP-completeness, by Prof Lucia Moura

JS Code Kata: Linked List

I’ve read these slides on the kata linked list, by Yitz Schaffer. The slide #13 talks about the transformations:

  • refactor: change form without changing behavior
  • transform: change behavior while changing form as little as possible

Also about the Transformation Priority Premise (TPP) (also in this month)

The Transformation Priority Premise

I’ve read, again, this article by Uncle Bob (Robert C. Martin)

Data structures

I’ve read the wiki page for

Also, The Big-O notation complexity cheatsheet

On benchmarks: Numbers every programmer should know and their impact on benchmarks

I’ve read this post on doing back-of-the-envelope calculations on publicly available benchmarks, written by Attila-Mihaly Balazs

Top Java IDE Keyboard Shortcuts for Eclipse, IntelliJ IDEA & NetBeans

I’ve read these slides on the topic of keyboard shortcuts for java IDEs, written by Oleg Šelajev

The hacker’s summer training guide – part 1

I’ve read this post by Paymill, that suggests which new languages to learn this summer: rust, go, elixir, ocaml, scala, livescript.

Applications built extremely right

I’ve read this post with a list of candidates for building nice products, written by Xavi Hidalgo.

Agile project seed. Infrastructure by default.

I’ve read this post on an agile seed project. Reminded me of the 12-factor app

What an agile developer should know

I’ve read this post by Xavi Hidalgo

Bad Apples that can destroy a team

I’ve listened to this podcast about the bad apples in a team. Presented by Vasco Duarte and Dominic Krimmer as the main speaker

How Scala compares with 20 other programming languages according to Reddit analysis

I’ve read this analysis of the language comparison, written by Oliver White

Javascript patterns book review

I’ve read this review by Ben Nadel on the book Javascript Patterns, by Stoyan Stefanov

Monogamous TDD

I’ve read this article on the fundamentalism of TDD, written by Robert C Martin

Encapsulating LocalStorage Access In AngularJS

I’ve read this article on why encapsulate the access to the localStorage, written by Ben Nadel

Anatomy of a zero-knowledge web application

I’ve read this article on a zero-knowledge web application, by the clipperz team

Refactorización de Código Legado Clase Maestra

I’ve watched this video about refactoring a legacy code in C#, by Danijel Arsenovski

Taming Javaagents

I’ve read these slides, again, from a conference I went to a few months ago about java agents. Written by Oleg Šelajev.

This is the repository containing the memory leak agent he talks about

Mathematics for Computer Science, Lecture 1

I’ve watched by the first recitation in this course, offered by MIT Open Course Ware (OCW). Recited by Tom Leighton

Programming Abstractions: Lecture 7

I’ve watched this lecture by Julie Zelensky about the comparison operator, recursion and a live coding session calculating the most ocurring anagram word in a file.

She uses small outputs to check the correctness of her programs to get short feedback cycles, even if they are manual.

5 Ways To Launch a JMeter Test without Using the JMeter GUI

I’ve read this guide on using jmeter without a GUI, by Dmitri Tikhanski

Clojure unraveled, chapter 5

I’ve read the fifth chapter, on the topics of Transducers, Transients, Metadata, Macros, Core protocols. Written by Andrey Antukh and Alejandro Gómez

A guide to the Basics of Data Structures

I’ve read this guide to data structures, covering the stack, the queue, the heap, the tree and the hashmap. Written by Radhika Ghosal

Government Abandonware

I’ve read this post on abandoned, public software that is not opensource. Dubbed by the author as “Government Abandonware”. Written by Bozhidar Bozhanov

The Art of Incremental Stream Processing

I’ve read these slides on incremental stream processing. The examples are in haskell and scala. Written by Mark Hibberd

I’ve read this insight into federated wikis by Mike Caulfield

Kafkapocalypse: a postmortem on our service outage

I’ve read this post-mortem analysis of the service outage at parse.ly, by Andrew Montalenti

Loving a Log-Oriented Architecture

I’ve read this post on experiences using the log-based architecture, by Andrew Montalenti. Cites the books I Heart Logs, and Big Data: Principles and best practices of scalable realtime data systems the essay The Log

A guide to Algorithmic Complexity

I’ve read this guide to algorithmic complexity, explaining Big-Oh notation (Big-Oh, Big-Theta, Big-Omega), with examples. Written by Radhika Ghosal

A guide to Recursion

I’ve read this guide to recursion explaining the gist of it. Examples include the Fibonacci sequence and the Hanoi Towers problem. Later, an introduction to the chaos theory and fractals. Written by Radhika Ghosal

Bootstrapped ClojureScript FAQ

I’ve read this FAQ related to bootstrapping clojurescript

Applying property-based testing on my binary search tree implementation

I’ve read this article, written by Manuel Rivero, on applying test-check (a property-based testing framework, similar to quickcheck) to a Binary Search Tree (BST) he did.

Do Extraterrestrials Use Functional Programming?

I’ve read these slides, an introduction to lambda calculus, the Turing machine and the Halting Problem. Later, continues to describe ways of solving problems in a functional way. Also performance and optimizations; monads as well. Written by Manuel M T Chakravarty

WIP Limits

I’ve read this post by Tomas Rybing

Applied capacity planning

I’ve read this post by Tomas Rybing.

Don’t Get Attached to Programming Languages

I’ve read this post by Mike Cavaliere

The Top 5 Skills of Rock Star Software Engineers

I’ve read this post by Cory Berg

5 Reasons to Use Protocol Buffers Instead of JSON For Your Next Service

I’ve read this article on Protocol Buffers, written by Michael Bernstein

Data Serialization Formats

I’ve read this comparison between MsgPack, JSON, Protocol Buffers, by Josh Szmajda.

Protocol Buffer Basics: Java

I’ve read this introduction to Protocol Buffers in Java, by Google

RESTful Considered Harmful

I’ve read this article, commenting downsides to using JSON / RESTful APIs, written by Tomasz Nurkiewicz

“Considered Harmful” Essays Considered Harmful

I’ve read this post, by Eric Meyer, on why “Considered Harmful” are harmful as well.

Keep Lambdas Cohesive

I’ve read this post with recommendations on keeping the java lambdas cohesive. Written by Venkat Subramaniam

The Joy of Flying Robots with Clojure

I’ve watched this video by Carin Meier at the OSCON 2013 about communicating with robots in Clojure

How to Learn TDD Without Getting Overwhelmed

I’ve read this article on learning TDD, by Justin Weiss

Kata - the Only Way to Learn TDD

I’ve read this article on learning TDD, by Peter Provost

Koan: Past Perfect

I’ve read this koan, past perfect, reflecting on the people who prefer the past over the present. Who think that the past was simpler than currently is.

Koan: Future Imperfect

I’ve read this koan, continuation from past perfect.

Why “Agile” and especially Scrum are terrible

I’ve read this article on downsides of Agile and Scrum, written by Michael Church.

Books read in 2015Q2

Jun 30, 2015 - 2 minute read - Comments - bookreading2015Q2self-study

Books I’ve read this quarter Q2 on 2015:

Books started, not yet finished (WIP):

Books I want to finish:

Books that have entered the queue:

Starting in 2015-Q2, I’m also writing here the list of books that I want to read.

Practical Object-Oriented Design in Ruby: Chapter 1

Jun 29, 2015 - 1 minute read - Comments - reading-clubaprendiceschapterpoodrsandi-metzmichael-feathersrubyobject-oriented-designoodedward-berarddesign-metricschurn

We’ve read the first chapter from the Practical Object-Oriented Design in Ruby, by Sandi Metz.

These are the concepts and links brought up during the discussion:

Walking on water and developing software from a specification are easy if both are frozen.

Edward V Berard, source is Wikiquote

Two cited papers on metrics for design:

The video for the ‘churn’ as a measure:

Brown-bag session: Refactoring legacy code

Jun 23, 2015 - 2 minute read - Comments - refactorrefactoringlegacy-codetrainingbrown-bag-sessionclientexperience-report

Today I have facilitated a brown bag session about refactoring legacy code applications, as this is the case with one of the applications we maintain and add new features to.

The contents of the session:

  • Briefly exposing the problem to the team, me taking the role of the Product Owner (PO)
  • Ask the dev team to add an easy feature
  • Do it without tests, as it was so simple that they thought they could do it (using mob programming)
  • Ask if they were satisfied by the patch / fix. Answer was yes.
  • Point out that there are regressions in the few lines of the patch
  • Repeat the session, starting with adding tests to guarantee the behavior is preserved (using mob programming)
  • Explain the technique of the golden master
  • Some more programming, until they start to see the light at the end of the tunnel
  • Small retrospective, including:
    • asking them their feelings when dealing with legacy code. The contents of this is pretty similar to the concepts that appear in the retrospectives, when talking about the legacy project / submodule.
    • what could I improve as facilitator or for the structure of the session

The repo can be found here.

I prepared a small script:

while test true; do
  git add --all;
  git commit --all -m "save process - uknown state";
  sleep 120;
done;

that saves the process and the progress, without disturbing the attendees. This allows you to follow the progress without any distraction. This idea was taken from a similar one from Xavi Gost 1

This same idea was also cited by someone else, if I recall correctly by Sandro Mancuso, saying that it would be a good idea to have a background git repository while working. IntelliJ IDEA already does something similar (and saves the events, e.g., when the tests are run, either red or green)


  1. Cannot find the source, it was about having a script to commit automatically each time you run the tests; if it was red while refactoring, it would do git checkout (to revert); Was related to the noFlopSquad ↩︎