Fortsätt till huvudinnehåll

Inlägg

Visar inlägg från mars, 2016

Test Driven Development of JavaFX

I just completed the  code.makery javafx-8 tutorial  by Marco Jacob. It took a couple of hours to complete and there is quite a lot of implementation done ahead of it being needed which make it a bit hard to follow. But overall I recommend it to get a good understanding how the different MVC parts in a JavaFX project interacts. Now, is it possible to use a TDD approach when developing a JavaFX application? Seaching the net a bit I found  this  presentation by Hendrik Ebbers that points to  TestFX . A test framework that provides "simple and clean testing for JavaFX". I am adding TestFX to the list of tools to be used during the development of my Record Collector Java mini project.

GUI prototyping with Scene Builder

Back in the days when I used to code HTML (for fun) I stayed away from WYSIWYG tools like FrontPage and Dreamweaver. When it comes to GUIs however I think it can be helpful to use a graphical layout tool. At least for prototyping. Today I did some prototyping with Scene Builder  in order to create a GUI for The Record Collector application. My impression so far is that it is easy to work with and speeds up the layout work a lot. Now let's see if I can turn The Record Collector to a good Model View Controller (MVC) project.

Swing on over to Java FX

Creating GUIs is something I do quite rarely. Hence when I started thinking about the GUI for the Record Collector application I opened up my old Java book and started reading about Swing. Today however I was informed that Java FX is preferred over Swing. Ok, then let's  Swing on over to Java FX .

TheRecordCollector is live on GitHub

The first commit for my new mini project has been pushed to GitHub. It can be found at:  https://github.com/Backhage/TheRecordCollector So far it doesn't contain much but I will be pushing as soon as I have something new. The "customers" will be my father and my uncle so I plan to demo something simple, but functional, to them as soon as possible.

New Java mini project

Today I started a new Java mini project. This one will be a bit bigger than usual. The target is to create an application for keeping a database of vinyl records. My father and uncle are both record collectors and are lacking an easy desktop application for keeping a record of their vinyls. During the development of this application I am planning to: Use IntelliJ  as IDE instead of Eclipse  that I normally use. Use Git  for version control. Add the project to  GitHub . Use  Mockito  for mocking the Data Access Object (DAO) when testing. Create a MySQL  database that is stored on a remote server and can be accessed over the net. Create a GUI for the application. So far I have installed IntelliJ and MySql locally. Set up a database and tried out some queries to see that it works. Also prototyped some SQL requests in Java.  One thing I realized that I really need to consider is how to handle exceptions due to database access issues. Also, I don't know of a good way to

Back to the world of functional programming

After some mini projects in Java (requesting bus departures using the local bus company's REST API and trying some fork/join optimizations) I returned to the functional programming course today. I must say that higher order functions ,  anonymous functions , and  traits  makes my head spin. Doing the exercises is quite challenging, but really fun! One thing that bugs me a bit though is thet  sbt  takes a bit too long to compile and run the tests ( real 0m8.395s ) which makes the design loop a bit longer than I would like. Remember that this is a really small project that only includes a couple of source files and no I/O. Compile and run the tests should take less than a second. I wonder how sbt scales. Anyway, great approach by Martin Odersky to advocate a test driven approach to the excersises!

The importance of good preparation work

This weekend I have been working on our staircase at home. The previous owners re-painted the staircase before they moved out. Unfortunately they "forgot" to do the preparation work properly so now the paint is flaking and looks terrible. Just as important as preparing before you paint is preparing your software before adding new functionality to it. When you are planning to add a new feature take a moment and ask yourself if your code is ready for it. The first coding task should be to ensure the new functionality fits well into the structure of the part of the code that is affected. There is a big possibility that some restructuring of the code is needed before it can be extended in a good way. Doing this will help you keep the code in a good condition. You don't want code that looks terrible and needs to be stripped down completely and "repainted, do you?

Hey kids! Stay away from POT.

I have been thinking about concurrency and parallelism a bit recently (hard not to when you are taking a course on functional programming and in your daily work develop software targeting a many-core processor). I thought it would be interesting to read up a bit on how to do parallelism in Java. After a bit of searching the net I found  this  Oracle article by Julien Ponge. The article starts by describing the usage of Plain Old Threads (POT) and the shortcomings involved in using them. It goes on describing the introduction of the concurrent packages in Java 5 which was later refined in Java 6 and finally introduces fork/join that was added in Java 7. The article has many examples and a provides a good overview of concurrency and parallelism in Java 7. I would recommend a read through for anyone planning to go beyond single threading in Java. Me, I am planning to do some benchmarking sorting 1 GB of random ints. Maybe the generation of the ints can be done in parallel as well...

Doing some Java POST requests

Next step in my JSON (GSON) Java mini project is to request some data from a web service using a Representational State Transfer (REST) API. The one I choose is the local bus/boat/train company's web service for requesting departure times. However, to be able to use their API I first needed to register at their website, then trying to figure out how to request OAuth2  tokens using Java HttpsURLConnection. So far I have gotten so far as to get a 400 (bad request) response. I am thinking I am mixing up url parameters and request properties. Will experiment a bit more. Conclusion so far, debugging this is tricky. Is there a better way than trial and error (yes, I have RTFM, which is unfortunately not up to date)?

Discuss these questions with your fellow developers

Reading the book "The Software Craftsman"  got me thinking. Some questions that I really would like to bring up with our team are: What does "well crafted software" mean to you? What characterises a good developer? What is the next thing you would like to learn/explore? Is it possible to learn that in your current position/role? Which tools do you use often that are time consuming/hard to use/bad in some way? What is stopping you from changing them to something else? Is our company good at attracting great developers (this can be sensitive, if no, what does that make us)? Would you still like to be a developer a couple of years from now? Why/why not? I have my mind pretty set up at the moment. But discussing the questions above might make me reconsider some of my current standings.

Java Reflection, setting private fields that does not have a setter method

I was a bit puzzled when I was experimenting with GSON and noticed that it was possible to create new objects and set their private fields (member variables) even though there were no public setter methods for the private fields and there was no constructor that could be used to set them either. When talking about it with a fellow developer he mentioned that probably Java Reflection  was used. Java Reflection can be used for a lot of things, see this comprehensive tutorial  by Jakob Jenkov for a good overview. Below I will show how it can be used to set the private class members in the class below: 1: public class Privates 2: { 3: private int privateInt; 4: private String privateString; 5: public int getPrivateInt() 6: { 7: return privateInt; 8: } 9: public String getPrivateString() 10: { 11: return privateString; 12: } 13: } An you can see there are no obvious ways how to set the members priv

Gradle and some notes on creating Java objects from JSON strings

This morning I spent my time commuting to work reading about a  Test-Driven Development Stack for Java . Tools mentioned were Maven, Jetty, Mockito, and JAX-RS. I wanted to learn some more about  Mockito  so I spent some time reading on their website where I found out about this build automation system called  Gradle  that can be used instead of Maven. Interesting I thought, let's try it out. So first things first. The Ubuntu repositories only contained a really old version of Gradle so I downloaded the binary distribution from the website. Installation consisted of the tricky task to decide where to extract the archive and set up my PATH to include the bin directory for Gradle. Then I thought that I wanted a plugin for Eclipse so I can create Gradle projects and have some parts automatically generated. After searching the web for a short while I found  Buildship  that  is a collection of Eclipse plug-ins that provide support for building software using Gradle. The easiest way

Parsing JSON in Java

My experience with Java is pretty limited. I took a Java course some ten years ago and professionally I have only been involved in one larger Java project. Therefore I thought it was time for a mini-project in Java. I prefer JSON over XML any day. Therefore I thought that a good mini-project would be to investigate the possibility to parse JSON using Java. After a few Google searches I decided to give Google's Java library  GSON  a try. GSON can be used to create JSON representations of Java objects and to create Java objects from JSON strings. I focused on the latter of these two. If you use Eclipse it is really easy to add the GSON library to your Java project. Just download the jar  and store it at a good location. Then in Eclipse, select the properties for your project and under "Java Build Path" -> "Libraries" press "Add External Jars..." and select the downloaded jar file. Here follows a simple test case using JUnit: 1: package se.th

Currying with Python

Currying is not something that I have used before. I encountered it recently during my dive into functional programming. So what is it, and can it be done using Python? I would describe Currying as a method to create specific functions by using a more generic function as base. If you are used to Object Oriented Programming (OOP) you can think of the generic function as the base class and the more specific function as the derived class. Let me show by example. Think of a function that multiplies every element in a list with a given multiple. This function would require two input parameters, the list and the multiple. In Python this could look like: def multiplyListElements(multiple, list): return [multiple*x for x in list] Now, imagine that you often want to multiply each element by three. You can do this by calling 'multiplyListElements(3, list)'. Or you can use Currying: def multiplyListElements(multiple): def f(list): return [multiple*x for x in lis

Being SOLID

In Software Development, what does SOLID refer to? SOLID is a set of principles for object oriented programming (OOP) and design. The five principles referred to are: Single responsibility principle (SRP) Open/closed principle (OCP) Liskov substitution principle (LSP) Interface segregation principle (ISP) Dependency inversion principle (DIP) To get a deeper understanding to what this means we have to go in to each principle, preferably by using examples. Since there are a lot of good comprehensive descriptions available online I won't write my own. Instead, I have collected links to good descriptions that are worth reading. SRP explained by Elizabeth Engelman OCP explained by Joel Abrahamsson LSP explained by Claudio Lassala ISP explained by Ricardo Sánchez DIP explained by Brett L. Schuchert

Not possible to submit assignments for "Functional Programming Principles in Scala"

If you plan to take the Coursera course " Functional Programming Principles in Scala" you should be aware that it is not possible to submit your tasks for automatic evaluation. All the course material including videos and tasks are available but you will not be able to verify that you have been able to solve the tasks correctly. I will however continue with the course. Not being able to submit is not a deal breaker for me since the tasks comes with pre-written test code making it possible to verify that your solution at least passes some basic functional tests.

Book review: The Software Craftsman

I just finished reading "The Software Craftsman" by Sandro Mancuso. Sandro is a sofware craftsman, author, and founder of the London Software Craftmanship Community (LSCC). He has worked on a number of different projects and companies ranging from small start-ups to large organizations. Software craftmanship as a term is something that I came across for the first time in 2013 when I signed the  Manifesto for Software Craftmanship . Around that time I also started reading books like "The pragmatic programmer" and "The clean coder" (both which I recommend by the way). Actually Robert C. Martin - the author of "The clean coder" - has written the foreword for "The Software Craftsman", in which he states that he felt like he could have written the book himself. And that's 100% true. If you have read "The Clean Coder" you will recognize most of the ideas and topics discussed. At least for the first half of the book. W

Surfing the web using only the keyboard

For quite some time I have been feeling frustrated every time that I need to move my hands from the keyboard to use the mouse. When surfing the web this usually happens all the time. Today however, I found a cure to this frustration, it is spelled Vimium. Vimium is an extension to Chrome that lets you surf the web using only your keyboard. Those of you that are familiar with Vim - the editor - will feel right at home. Others will learn the keys quite quick. And if you find yourself wondering which key that does what, just type '?' and Vimium will display a help splash screen with the most common keys and what they do. Vimium will let you scroll, click links, select and copy, etc just using your keyboard. To me this is big relief and I really recommend that you give it a try. Visit the Vimium homepage

Switching keyboard layout from Qwerty to Dvorak, is it worth it?

For the last two months I have been using Dvorak, or actually Svdvorak (Dvorak with a Swedish twist). The first two weeks or so were pure frustration. I literally had to force my fingers to press keys that felt completely wrong. Everyday I practiced using the site http://learn.dvorak.nl/ and slowly I became faster. Today, after using Svdvorak everyday for over two months I feel that my typing speed is pretty okay again. However, my accuracy is still quite bad. I would estimate that I type about 90 - 95% of the characters correctly. Which means that I have to erase and re-type almost every tenth character. Quite frustrating when you have been completely fluent with Qwerty for over 20 years. In summary, I will continue using the Dvorak keyboard layout, sooner or later I am sure that I will be totally comfortable with it, and already today most of the frustration is gone. However, if you feel totally comfortable with Qwerty today I would recommend that you stick with it. The big advan

Time for some functional programming

I have never really taken the time to really learn functional programming. In 2006 I took a course in Haskell but really never bothered to understand what I was doing. Now that I have been developing in imperative languages like C, C++, Java and Python - both profesionally and on my spare time - since 2008 I feel like it is time to give functional programming another shot. A couple of days ago I signed up for the Coursera course "Functional Programming Principles in Scala" that I will spend the upcoming weeks getting through. Besides that I also tried some Erlang and Haskell just for the fun of it. Will give a review on the Coursera course in a couple of weeks.

Source Code Formatter

I just found this nifty site: http://codeformatter.blogspot.se/ What it does is that it lets you paste code into a text box, which it then formats to something that you can copy/paste to your blog in order to have source code displayed in a nice way. Here is an example: 1: #include <stdio> 2: int main(int argc, char** argv) 3: { 4: std::cout << "Hello, world!" << std::endl; 5: return 0; 6: } Pretty nice right? Add a little syntax highlighting and we're all set.