30 September 2015

New Classes in Java 8

Jumping Spider #1Java (SE) 8 was released on the 18th of March 2014. Unlike previous releases it did not have a code name like Tiger or Dolphin. Spider was proposed as unofficial name on Code Ranch because of "8 legs, and a strong association with webs." It was an exciting release with huge changes, with probably similar or even larger impact than Java 5, which brought Generics. The new features (and the ones that did not make it into Java 8 yet) show that Java is on its way to be a modern and productive programming language.

Numbers
The rt.jar and other JARs located in the lib folder of the JRE contain many classes. For each new release I take a look at the new (public) classes. The list of new classes complements the list of new language features. Java 8 adds more than 1000 public classes, mainly in the packages javafx.*. Without JavaFX there are 251 added classes, similar to Java 7.

Java Classes by JDK/JSE
Lambdas and Streams
The major library changes are to support Lambda Expressions and the related Stream API. The new java.util.function package contains all types of possible function types.
java.lang.FunctionalInterface

java.lang.invoke.LambdaConversionException
java.lang.invoke.LambdaMetafactory
java.lang.invoke.MethodHandleInfo
java.lang.invoke.SerializedLambda

java.util.function.
BiFunction                Function                   Predicate
ToDoubleBiFunction        DoubleFunction             BiPredicate
ToIntBiFunction           IntFunction                DoublePredicate
ToLongBiFunction          LongFunction               IntPredicate
                                                     LongPredicate
BinaryOperator            DoubleToIntFunction
DoubleBinaryOperator      DoubleToLongFunction       Supplier
IntBinaryOperator         IntToDoubleFunction        BooleanSupplier
LongBinaryOperator        IntToLongFunction          DoubleSupplier
                          LongToDoubleFunction       IntSupplier
Consumer                  LongToIntFunction          LongSupplier
BiConsumer                ToDoubleFunction
DoubleConsumer            ToIntFunction              UnaryOperator
IntConsumer               ToLongFunction             DoubleUnaryOperator
LongConsumer                                         IntUnaryOperator
ObjDoubleConsumer                                    LongUnaryOperator
ObjIntConsumer
ObjLongConsumer
The Streams are in the package java.util.stream,
Stream
Stream$Builder
StreamSupport
BaseStream
DoubleStream
DoubleStream$Builder
IntStream
IntStream$Builder
LongStream
LongStream$Builder

Collector
Collector$Characteristics
Collectors
as well as some additions to java.util for splitting and collecting.
java.util.DoubleSummaryStatistics
java.util.IntSummaryStatistics
java.util.LongSummaryStatistics

java.util.Spliterator
java.util.Spliterator$OfDouble
java.util.Spliterator$OfInt
java.util.Spliterator$OfLong
java.util.Spliterator$OfPrimitive
java.util.Spliterators
java.util.Spliterators$AbstractDoubleSpliterator
java.util.Spliterators$AbstractIntSpliterator
java.util.Spliterators$AbstractLongSpliterator
java.util.Spliterators$AbstractSpliterator
java.util.SplittableRandom

java.util.StringJoiner
Java 8 Date and Time API
The next big change is the new date and time API. It contains a lot of new classes to model and use dates and time in your code.
java.time.Clock                     ...format.DateTimeFormatter
java.time.DateTimeException         ...format.DateTimeFormatterBuilder
java.time.DayOfWeek                 ...format.DateTimeParseException
java.time.Duration                  ...format.DecimalStyle
java.time.Instant                   ...format.FormatStyle
java.time.LocalDate                 ...format.ResolverStyle
java.time.LocalDateTime             ...format.SignStyle
java.time.LocalTime                 ...format.TextStyle
java.time.Month
java.time.MonthDay                  ...temporal.ChronoField
java.time.OffsetDateTime            ...temporal.ChronoUnit
java.time.OffsetTime                ...temporal.IsoFields
java.time.Period                    ...temporal.JulianFields
java.time.Year                      ...temporal.Temporal
java.time.YearMonth                 ...temporal.TemporalAccessor
java.time.ZonedDateTime             ...temporal.TemporalAdjuster
java.time.ZoneId                    ...temporal.TemporalAdjusters
java.time.ZoneOffset                ...temporal.TemporalAmount
                                    ...temporal.TemporalField
...chrono.AbstractChronology        ...temporal.TemporalQueries
...chrono.ChronoLocalDate           ...temporal.TemporalQuery
...chrono.ChronoLocalDateTime       ...temporal.TemporalUnit
...chrono.Chronology                ...temporal.UnsupportedTemporalTypeException
...chrono.ChronoPeriod              ...temporal.ValueRange
...chrono.ChronoZonedDateTime       ...temporal.WeekFields
...chrono.Era
...chrono.HijrahChronology          ...zone.ZoneOffsetTransition
...chrono.HijrahDate                ...zone.ZoneOffsetTransitionRule
...chrono.HijrahEra                 ...zone.ZoneOffsetTransitionRule$TimeDefinition
...chrono.IsoChronology             ...zone.ZoneRules
...chrono.IsoEra                    ...zone.ZoneRulesException
...chrono.JapaneseChronology        ...zone.ZoneRulesProvider
...chrono.JapaneseDate
...chrono.JapaneseEra
...chrono.MinguoChronology
...chrono.MinguoDate
...chrono.MinguoEra
...chrono.ThaiBuddhistChronology
...chrono.ThaiBuddhistDate
...chrono.ThaiBuddhistEra
And Other Classes
There are several new classes all over the place. The most notable are:
  • Reflection for Type Annotations.
  • Finally a Base 64 encoder and decoder.
  • Optional.
  • CompletableFuture and StampedLock.
java.lang.annotation.Native                      java.io.UncheckedIOException
java.lang.annotation.Repeatable
                                                 java.net.URLPermission
java.lang.reflect.AnnotatedArrayType
java.lang.reflect.AnnotatedParameterizedType     java.sql.DriverAction
java.lang.reflect.AnnotatedType                  java.sql.JDBCType
java.lang.reflect.AnnotatedTypeVariable          java.sql.SQLType
java.lang.reflect.AnnotatedWildcardType
java.lang.reflect.Executable                     java.util.Base64
java.lang.reflect.MalformedParametersException   java.util.Base64$Decoder
java.lang.reflect.Parameter                      java.util.Base64$Encoder

java.security.DomainLoadStoreParameter           java.util.Calendar$Builder
java.security.KeyStore$Entry$Attribute           java.util.Locale$FilteringMode
java.security.PKCS12Attribute                    java.util.Locale$LanguageRange
java.security.spec.DSAGenParameterSpec
                                                 java.util.Optional
java.security.cert.CertPathChecker               java.util.OptionalDouble
java.security.cert.PKIXRevocationChecker         java.util.OptionalInt
java.security.cert.PKIXRevocationChecker$Option  java.util.OptionalLong

java.util.spi.CalendarDataProvider               java.util.PrimitiveIterator
java.util.spi.CalendarNameProvider               java.util.PrimitiveIterator$OfDouble
java.util.spi.ResourceBundleControlProvider      java.util.PrimitiveIterator$OfInt
                                                 java.util.PrimitiveIterator$OfLong
java.util.concurrent.atomic.DoubleAccumulator
java.util.concurrent.atomic.DoubleAdder
java.util.concurrent.atomic.LongAccumulator
java.util.concurrent.atomic.LongAdder

java.util.concurrent.CompletableFuture
java.util.concurrent.CompletableFuture$AsynchronousCompletionTask
java.util.concurrent.CompletionException
java.util.concurrent.CompletionStage
java.util.concurrent.ConcurrentHashMap$KeySetView
java.util.concurrent.CountedCompleter

java.util.concurrent.locks.StampedLock
Additional changes cover additions to UI capabilities - JavaFX is now part of the JRE. The Java Language Model has been updated (javax.lang.model) and Rhino has been replaced by Nashorn (package jdk.nashorn). There are more changes, e.g. stronger security algorithms, but these do not show up as new classes.

Summary
Java 8 brings big changes for the language, finally adding closures to Java. This is as ground breaking as Java 5's Generics. Lambdas and Streams will change the way we write Java and allow a more functional style in our code.

You can download the complete list of all classes available in Java 8. Each class name is annotated with [release] showing the release it first appeared, e.g. java.lang.annotation.Annotation [5]. Package access classes are marked by a lowercase p, e.g. java.lang.CharacterName [7p].

24 September 2015

What I Learned on Tour

When you think about doing your own Software Journeyman Tour I guess the most interesting questions is what you will learn. After all such a tour is mainly about learning and seeing how other people work. The time (and money) put into such a tour should be worth it.

My Expectations
To be fair I need to discuss my expectations first. In retrospect my expectations were not clear. I did not follow Daniel's rule and had not defined an explicit learning goal. (See my previous discussion on how to go on tour for details.) I had expectations that I would pair with fantastic masters of our craft, who are much superior to me, and see astounding things. That was not measurable and definitely not clear enough. There was no goal and I did not align my plans accordingly. Obviously my expectations were too high, sigh.

When starting my tour I knew TDD well and had been developing professionally since more than a decade. In contrast to that many of my pairing sessions were basic. I helped developers to create their first unit test. Maybe I should have done the tour five years earlier. Daniel even proposed that the perfect time for a Journeyman Tour might be for young developers with two to three years of experience.

Lina Bo Bardi, SESC PompéiaA friend called me a master and remarked that masters do not go rounds any more. They do not learn like that (Smi's rule). I am no master but there seem to be diminishing returns for a learning tour if you are already advanced in some areas. Some coder friends have also expressed this concern.

Concrete Learnings
To give you an impression here is a list of all concrete learnings of the first and second week. I spent ten days pair programming with four different people in this time. While it is hard to express the real learning, here are the things I found interesting enough to write down during the sessions:
  • Learned about little HTML5 games and their way of publishing and making money.
  • Brushed up my IntelliJ IDEA short-cut knowledge.
  • Improved my Mechanics of pair programming, how to deal with exhaustion and zoning out.
  • How to handle dependencies with local and shared lock files.
  • Startup developers are "poor" creatures because they support their customers, do operating, fix bugs, help less technical co-founders and have very little time for actual development.
  • I coded Python for the first time - or more accurate - paired on Python code.
  • oh-my-zsh with plugins is an useful shell extension.
  • I relearned Vi as it had been many years since I had last used it.
  • I paired on existing C# code for the first time.
  • The "Rename Overloads" is a nice function of Visual Studio (or Resharper) that I had not seen in Java yet.
  • When the current Pomodoro finishes, run the tests.
  • I learned more about dependencies of OSGi bundles and their problems.
  • Deploying OSGi bundles in an OSGi aware server is a real pain.
  • It is possible to create a cash flow calculation and business plan in a pair as well.
If I multiply these items with the total of 13 weeks, I get around 80 to 100 interesting things I saw. So yes, a Journeyman Tour is a great way to see many things. I worked on many things for the very first time in my life, e.g. I had never even seen Python, C#, VBA or Typescript code or developed for Google App Engine or opened Netbeans etc. I gained lot of experience on many different things in a short time. Maybe the experiences lacked depth. For example how much learning can you expect from two days Typescript? I spent a maximum of three days in a company working with one or sometimes with two different developers. Maybe I should have worked at least a full week on one topic to get deeper insights. Daniel spent a whole week at each host and considers it the perfect length for a Journeyman visit.

Practice
The tour gave me a lot of practice in different areas, maybe I had even more practice than learning new things. I had little pair programming experience before. On my tour I pair programmed all day, each day for almost three months. That improved my pair programming skills by far. In the end of the tour I was able to get in sync with a new pairing partner quickly. Since my tour I love pair programming. I feel stupid when working alone, so I rarely do it nowadays.

Next I practised getting productive in a new project. By running Hackergarten in Vienna for more than a year I was already comfortable with that. On my tour I figured out how to ask for the right amount of context without slowing down my pair with too many questions. Today I am confident to be productive in a new project or technology within a few hours - with the help of a pairing partner who knows the area of course. This conforms to Corey Haines' observation that he learned most how to start with an unfamiliar code base immediately. While this is very helpful for my current occupation as Code Cop and Freelance Code Mentor, I do not know how much this would help you during regular development, where you stay in the project for months of even years.

Luxury Gold Ring Designs For Golden JewelryValue
I understand the value of practice and like working on code katas and other practice exercises. Still my improved IntelliJ IDEA short-cut-fu feels less valuable than working in Typescript because there was nothing new in the former and everything new in the later. I know that my feeling is wrong. The mastery of IntelliJ short-cuts is important and helps even when working in other languages (as long as I stay with JetBrains products) while the basics of another static, object orientated, main-stream language are forgotten soon (unless I get into a real project, which I did not).

Some of my learnings were not interesting, e.g. creating an Excel cash flow calculation was not what I expected to do nor had ever wanted to. Working with my pair on the tasks he or she had chosen forced me to a few boring things, that I hated and would have never done on my own. It was painful but definitely broadened my horizon. Maybe these are the most valuable experiences because I would never get them otherwise. Or maybe these experiences are useless because I will never do such things and I wasted a few days of my life. I am unable to decide.

Satisfaction
My expectations partly fulfilled by learnings and practice, which both have a vague value, result in a certain feeling of satisfaction. Still many questions remain. Am I satisfied with the outcome of my tour compared to the time and money involved? What is the value of the things I learned? Could I have learned more useful things in a shorter time? And even if, would I have learned it (or done something else instead)? Maybe more interesting to you is if you would be satisfied with such a tour?

So let us look at some hard facts again. Before my tour I got in touch with 32 companies. During the 60 days of my tour 16 companies hosted me and I paired with 26 people. I further attended two conferences and 15 user group meetings in the evenings. My overall statistics shows me 40% of great pairing sessions which were awesome and where I had insights into TDD or a lot of fun. Then there were 40% of tolerable pairing sessions which were sort of OK. The remaining 20% were bad sessions, where I did not learn much or even felt like crying. It is true that you learn from everybody, even from very beginners, but e.g. handling difficult people was not on my list of learning goals.

Conclusion
Even with some of my expectations not satisfied, my Code Cop Journeyman Tour was one of the most interesting and most intense times of my life. Its overall experience was awesome. Half of the time I did great work while pairing with amazing people. I learned around a hundred new things and had a lot of practice. In comparison, had I stayed with my previous employer I would have experienced a few great days and learned a few new things during regular work. The tour made a massive difference for me and I am glad I went for it. Until today I plan for single Journeyman visits from time to time. Last year I spent three days pair programming for food. While this is less than 2% of my total work time, I am still proud of myself that I kept the spirit of the tour.

just do it.Final Recommendation
If you came here to check if it is worth to go on tour then my answer is yes. A Pair Programming Tour is a great thing to do. Even if you go for a single month, visiting only four companies for a few days each, you will see a lot of new things and work with people you never worked with before. It is the right thing to do. Now go and do it!

17 September 2015

How to Journeyman Tour

It has been two years since I did my own Journeyman Tour. It has been a blast but I never took the time to write about some topics besides the actual things that I did back then. Recently I was reminded of the topic by Lennart's tour and friends asking me about it as well. So I need to catch up and discuss some of my findings. This article is not about the tour itself, but about things to be considered if you plan your own Journeyman Tour.

What to Expect
Back in 2013 I first analysed Corey Haines's Pair Programming Tour in 2008 to get an idea what it means to do such a tour. Then I defined my personal, particular rules of my own Code Cop Tour. My rules were supposed to reduce uncertainty and help me achieve my objectives, but they were not specific enough. (I will write about that later.) During a Journeyman Tour one objective is about learning, so you need to define your learning goal (Daniel's Rule). Maybe I did not have that, or I had the wrong one, or my other tour preparations were not aligned with my objectives. More discussion would have helped me to get a better picture what might happen during a tour. So if you plan to go on tour yourself, I recommend you discuss your plans with people who have done it before.

Planning sessionPlan Ahead
First you need to select the area you want to visit. I stayed local in my city. Others toured their country or continent and a few visited the whole world, e.g. working at companies both in Europe and the United States. Adding conferences as speaker or attendee is a great thing as well. Based on the decided locations and dates I created a schedule. Be aware that a Journeyman Tour, while being a great thing to do, is also exhausting, and in fact hard work. You need to plan accordingly. I had planned too many sessions in too little time. You need to plan for some free time each month as well.

Host Companies
Finding hosts is the hard part. See my list how to find hosts and sell a Journeyman Tour to management. Some hosts have specific legal requirements. You need to be prepared for some legal hassle. In Austria and Germany the legal background for unpaid work is the Volontariat, which is primarily used for education. But I am not a lawyer, please do not ask me for details.

Silence PactSign Non-disclosure Agreement
All larger companies asked me to sign NDAs. I signed them because I was not interested in their customers, products or other details. I wanted to see the way they worked, how the used technologies and the engineers working there. I even brought a generic NDA with me if a small company or startup did not have any template. I respected the agreement and did not talk about any details we had worked on ever. That is the reason that my reports of the tour are generic and lacking details. I always asked for permission to mention the company in my blog and let them review and approve my posts before publishing it.

Respect the Host Company (Security) Policies
Having worked at large corporations I understood the need for security of most host company representatives. As they had no idea what a visit of a Journeyman meant, they had concerns. My rules were never to work alone. Beside security concerns it helped me keeping focused on pair programming. Obviously I did not need any access codes, passwords or other security related information. While I brought my private laptop to take notes, I even asked for permission to plug it into electricity. Some companies do now allow private IT equipment to be operated inside their premises. While most of these issues might sound silly to you, it is of utmost importance to make potential host company representatives feel secure if they are going to allow an outsider in. Further I wanted to respect any company policy of the host while I stayed there.

Finding a Future Job
Working for some time at a company is a great way to figure out if it is a place you would like to stay. Some host companies even implied that depending on the report of my pairing partner they would offer me a job. This could lead to problematic situations. If I would not apply for a job after my visit, it would be like saying "your company sucks". A company hosting a journeyman is always a great company. I recommend rejecting any discussions regarding future jobs by saying that your visit is not about a job but about learning and sharing (Thomas' rule).

My Piggy BankExpect No Compensation
Some people asked me if it paid off to go on tour. While it is possible to have a paid tour, all the Journeymen I know did not get any money for their work. The classic Journeyman Tour is a self-funded journey of discovery and sharing. Even when provided with food and a room to sleep, a tour is not a cheap trip. You still need to cover additional costs, e.g. public transport. During my tour one company wanted to pay me because they were afraid to be accused of unreported employment. In another company the team lead had to pay for my lunch himself because it was impossible to get the money from the company. When I was away from home, I asked the host company to pay for my hotel at least.

Journeyman Work
Daniel told me this story: During his tour in 2013, a company showed interest in hosting him. When discussing terms of his visit, it turned out that the company wanted to get professional training for free during his visit. As working together and sharing knowledge is the base idea of a Journeyman Tour, it is difficult to draw the line between regular exchange and abuse. But extensive training of the host company's stuff for free is definitely out of scope. During my tour I pair-programmed (and pair-designed and pair-tested) with developers and occasionally gave a presentation about the background of my tour. In one case I prepared a presentation of the things I had learned during my visit. I did not engage in any other internal activities like facilitating internal Coding Dojos or giving presentations on other topics, and nobody asked for it. Wherever you draw the line, you should think about it before starting your tour.

That information together with my older articles should get you started in your own Journeyman Tour! Read more about the tours of other people, e.g. Daniel Temme, Andy Waite and recently Lennart Fridén.