Pages

Monday, August 13, 2018

3 Reasons not to be Mutable!

In this short article, while talking about immutability, I will also try to convince you why functional programming is the answer to your problems.

Read More...

Tuesday, August 7, 2018

pair vs mob vs plain old programming

I want to share my experience on pair, mob and plain old programming. This is also about eXtreme programming practices, Agile and dogma around them. It’s third part of my series on remembering what agile meant.

Read more...

Thursday, August 2, 2018

Case for and against TDD

I am not sure if same applies for other engineering practices but software engineering suffers from dogmatism a lot.

My problem with TDD is with consultants of TDD. They make bold claims about TDD and offer only little practical proof and label criticism as unprofessional.

Read More...

Tuesday, July 24, 2018

What was Agile?

Agile has become a prefix for whatever. Let’s remember what it was about.

Is everything agile?

Here are a couple of things agile for you. It obviously starts with “Agile Software Development” and ...

Read more

Tuesday, July 21, 2015

Java 8 lambda examples II

Generate an array of random Integer values:
   private static final Random random = new Random();  
   public static Integer[] generateRandomIntArray(int size) {  
     return IntStream.range(0, size).map(i -> random.nextInt(size)).boxed()  
         .toArray(Integer[]::new);  
   }  

Reverse an array:
     IntStream.range(0, randomNumbers.length / 2)  
         .forEach(i -> swap(randomNumbers, i, randomNumbers.length - i - 1));  

Do bubble sort:
     IntStream.range(0, items.length)  
         .forEach(i -> IntStream.range(i + 1, items.length)  
             .filter(j -> items[i]> items[j])  
             .forEach(j -> swap(items, i, j)));  

Friday, July 3, 2015

Testing your main method

I wrote a lot of simple applications, mostly to just try things out, that run on text console and for user interactions use System.out.println and System.in. An issue is how to test these programs. Here is a simple way. Move your logic from your static main method to the object and parameterize the System.in & System.out. Like from this :
 public class ShouterMain {  
   public static void main(String... args) throws Exception {  
     String id = UUID.randomUUID().toString();  
     final MulticastSocket socket = new MulticastSocket(4444);  
 ...  

to this:
   public static void main(String... args) throws Exception {  
     new ShouterMain(System.out, System.in).doMain();  
   }  

To test use ByteArray Streams:
     final List<String> firstClientLines = new ArrayList<>();  
     try (  
         PrintStream firstOut = new PrintStream(new ByteArrayOutputStream()) {  
           @Override  
           public void println(String str) {  
             firstClientLines.add(str);  
           }  
         };  
         InputStream firstIn = new ByteArrayInputStream(new byte[]{});  
     ) {  
       new ShouterMain(firstOut, firstIn).doMain();  
       Assert.assertEquals("Someone shouted: 'I am Second!'", firstClientLines.get(0));  
     }