czwartek, 18 maja 2017

GeeCon has arrived! Day one

GeeCon 2017 is finally here!. Packed with presentations, ranging from higher management talking about how organisations work in a big picture to a "geeky" CPU internals. Everything in a Multikino, providing what's needed for a presenter (and attendees) spiced up with a really good catering. 

Here's my very short report on what I saw today.

Keynote - David Moore

A very interesting presentation, especially taking into account that usually higher management talks are a bit.. boring (so to speak ;-) ). He talked about approaching refactoring / replatforming on an organisational level. Most of his observations were exactly aligned with my experiences, both concerning things that work and things that don't.
What is worth remembering is Convay's law - "products mirrors organisations". Tech organisation with bad communication or bad structure will always create lousy products. Period! Leaders of any sort should also take with themselves the statement that their role is usually to hire great people, trust them, let them loose and get the hell out of the way ;-)

Caching - Michael Plod 

General introduction to caching in typical business web applications, that is applications that can't allow "eventual consistency". Some basic concepts (local cache, clustered, distributed, local off-heap), some examples, some real-world cases (issues). Overally, nice presentation from both technical (way the presentation was delivered) and meritorious point of view. Some (salut, Grzegorz!) would say that nothing new / leading edge was presented, but in my opinion it was worth attending anyways. Perhaps the title - "best practices and gotchas" suggested something different, that is much more detailed, technical presentation? I personally especially liked that whole speech was focused around what basic questions should be asked when introducing a cache into a system and how these should be answered, step by step.
Last but not least - quoting the Author, remember that a cache will not solve performance issues of an application - first optimise, than introduce local cache, then eventually a distributed one (to tackle scalability issues etc.). And never ever implement your own cache! :-)

Domain Driven Design - Cyrille Martaire

Brief introduction to DDD, mixed with funny cats and some jokes (5 minutes into presentation - we're done, thank you!). Basic concepts (ubiquitous language, Value Objects, Bounded Context). Some examples to help the audience visualise the ideas behind DDD. From my perspective the presentation lacked a clear example, comparing small application (MVP) written with and without DDD. Such exercise would be very helpful to see a value that can be brought by introducing DDD and which problems can be solved. Then it would be much easier to decide if benefits outweigh additional costs.

How SCRUM moved away from developers - Matthew Brylka

By reading a title - and just a title - I understood that the presentation will be a critic of SCRUM implementations in many companies, where the process no longer helps deliver value but s rather a good excuse for added paperwork loved by all sorts of bureaucrats. What I got instead was mostly overview of SCRUM principles (with some emphasis on what is not there) along with particularly interesting "how to succeed" section. Two thoughts from the presentation to be remembered:
  • Use agreements with stakeholders instead of contracts / demands
  • Technical excellence, debt backlog and refactoring are constant practice - every manager should understand this, instead of pushing refactoring further, deprioritising it or asking for a separate, estimated task (that could be saved in the backlog forever)
After this presentation I got an impression that besides developers also line managers and allmighty architects of all sorts should attend the GeeCon conference! ;-)

Developer Plantations - Wojciech Seliga

Writing code (aka "coding") is becoming a commodity. Soon everyone after few months of training will be able to write *something*, just as now literacy is common compared to XIX century. In order to stay ahead of the crowd, we (meaning - skilled engineers) need to understand why is a product created, besides knowing how and what it is. These are main thesis for the future of our industry. A bit of a "lifestyle" presentation, without any technical aspects. Worth listening to just for a glimpse of a different perspective (different than another tool, library or architecture).


To sum up - an interesting day. On day two I plan to attend some more "technical" presentations. Stay tuned!

piątek, 5 maja 2017

Memo - accessing files in a web application

Sometimes the easiest things are also the easiest to miss (or to forget :-) ). Therefore, in order to have this once and for all in one place - the quickest guide how to access files in a servlet environment (Spring Boot application in my case).

1. Classpath resource

A file that is present in a classpath (typically /WEB-INF/classes, /WEB-INF/lib).
Can be anything, most probably a configuration file that is packed with WAR during package preparation stage. In case of good old Maven - all of the resources (by default src/main/resources) will end up in the classpath. Access - via context class loader.
For example:

2. Web resource 

All of the web application files - including static content (images, styles, html, ...) and files that are loaded into classpath (JARs from /WEB-INF/lib etc.) can be accessed this way. The only requirement is the presence of a ServletContext. 
PRO TIP: In a Spring application, the ServletContext can be simply autowired into a service requiring it. 
For example: 
As a last word - be __very__ cautious when planning to use ServletContext.getRealPath(). Why? Just take a look here: http://stackoverflow.com/questions/12160639/what-does-servletcontext-getrealpath-mean-and-when-should-i-use-it

wtorek, 11 kwietnia 2017

Java 8 for late-adopters ;-)

I've just realised that Java 8 is already 3 years old! For a general-purpose language version, this happens to be a lot.

What's even more striking is that there are still a lot of projects that haven't been migrated to the newest (but already mature) version. There are in fact many projects that still use first "real" JRE, that is version 5 which introduced generics, enums, autoboxing, improved concurrency and all of the stuff nowadays recognised as a minimum standard.

Why is that? Well, sometimes is because cost of migration, especially for big, monolithic systems, is deemed to large. Sometimes that may be true. However, often the cost is overestimated or the benefits are underestimated. Therefore in this short post I'd like to present some Java 8 features that in my opinion can really bring substantial benefits and at the same time provide good arguments to justify the migration:

1. Lambdas aka functional programming for the masses.

Yes, we have Guava's Function. Yes, it's a bit of functional programming. But let's just compare this:
and this:

How cool is that ? And it's only a beginning! Java 8 added a real functional programming  API, as advanced as it can be taking into account object-oriented nature of the language and dreaded "backwards compatibility".
In order to fit some functional programming into Java, following concepts had to be introduced:
  • functional interfaces - basically a "type" for a "function"
  • new "->" notation, with following syntax rules:
    • types of the parameters are optional
    • parentheses around the parameter are optional if you have only one parameter
    • curly braces are optional (unless multiple statements are present)
    • return” keyword is optional in case of a single expression that returns a value
  • method references (with "::" operator)
It's really a lot of fun and a lot less of a boilerplate code. You simply need to try it for yourself :-) 

2. Streams and parallel collections

Basically streams (implementing Stream interface, who would guess?) are Iterators on steroids. Why on steroids? Because streams support:
  • out of the box parallel execution!
  • map / filter / reduce pattern
  • functional "iteration" as old friend - forEach method
  • primitive (Int / Double / Long) counterparts for even greater performance
Map / filter / reduce together with lambdas effectively eradicates the need for Guava's FluentIterable and consortes. Sorry! The standard library always wins!
Built-in parallelization and lazy evaluation brings the need to collect, join, group or partition. This is also provided. Nice! Just take a look at this example - joining User names:

3. Joda (well, almost) date / time

The only thing that can be said is at last! LocalTime, LocalDate, LocalDateTime and ZonedDateTime along with a reasonable API (copied from Joda :-) ). Plus fast-and-easy creation (now(), toInstant()). Especially the last one is nice, allowing for a fast migration:
 I wish this had been added years ago!

4. Misc (Optional, Base64 and others)

  • Everyone knows (or at least should know) the Optional class. Now available in the standard library! 
  • Everyone had at least once a need to use Base64. Now available in the standard library as well! 
  • Tuples! At last!
  • No more Permanent Generation (one JVM parameter less, heh)
Maybe it's not something that would change one's life, but definitely something that should have been in Java, like, since beginning.

Java 8 brings a lot. Really, in my opinion it's the first "REAL" update since version 5.0. There is much more than mentioned in this short post, I encourage everyone to go and try (and then try to persuade the management to migrate projects as well...).