Yegor Bugayenko's Blog, page 19

July 10, 2017

How I Would Re-design equals()

I want to rant a bit about Java design, in particular about the methods Object.equals() and Comparable.compareTo(). I've hated them for years, because, no matter how hard I try to like them, the code inside looks ugly. Now I know what exactly is wrong and how I would design this "object-to-object comparing" mechanism better.

[image error]L'ultimo capodanno (1998) by Marco Risi

Say we have a simple primitive class Weight, objects of which represent the weight of something in kilos:

class...
 •  0 comments  •  flag
Share on Twitter
Published on July 10, 2017 17:00

July 3, 2017

Am I a Sexist?

Recently I said a few words in my Telegram group about "women in tech," which led to some negative reaction on Twitter. I believe I owe my readers an explanation. Some of them already got confused and came to me with the question: "If you're so much against slavery, where is this male chauvinism coming from?" Let me explain what's going on. Indeed I am a big fan of freedom, but recent hysteria around gender equality is not helping us to become more free. Instead it...

 •  0 comments  •  flag
Share on Twitter
Published on July 03, 2017 17:00

June 26, 2017

My Work Environment

I was asked in my Telegram Group which tools and hardware I use in my daily work. Here is the full list of what I have and even how much I paid for them. Maybe it will be helpful for someone.

[image error]
MacBook Pro Retina, 15-inch, Late 2013, 2.3GHz/16Gb/512Gb ($2,900) with MacOS Sierra. I bought it over three years ago and don't want to replace with a new one, simply because rumors are its quality is very low. My smartphone is iPhone 6s.

[image error]
IntelliJ IDEA Ultimate ($499 free) for Java projects....

 •  0 comments  •  flag
Share on Twitter
Published on June 26, 2017 17:00

June 21, 2017

Object-Oriented Declarative Input/Output in Cactoos

[image error]

Cactoos is a library of object-oriented Java primitives we started to work on just a few weeks ago. The intent was to propose a clean and more declarative alternative to JDK, Guava, Apache Commons, and others. Instead of calling static procedures we want to use objects, the way they are supposed to be used. Let's see how input/output works in a pure object-oriented fashion.

Let's say you want to read a file. This is how you would do it with the static method readAllBytes() from the...

1 like ·   •  0 comments  •  flag
Share on Twitter
Published on June 21, 2017 17:00

June 12, 2017

DynamoDB + Rake + Maven + Rack::Test

In SixNines.io, one of my Ruby pet web apps, I'm using DynamoDB, a NoSQL cloud database by AWS. It works like a charm, but the problem is that it's not so easy to create an integration test, to make sure my code works together with the "real" DynamoDB server and tables. Let me show you how it was solved. The code is open source and you can see it in the yegor256/sixnines GitHub repo.

How to bootstrap DynamoDB Local

First, you need to use DynamoDB Local, a command line tool...

 •  0 comments  •  flag
Share on Twitter
Published on June 12, 2017 17:00

June 5, 2017

Gluten-Free Management Recipes

We live in the era of organic food, eco-friendly toilets, zero-emission cars, and harassment-free offices. Our management practices have to keep up—they must be zero-stress, conflict-free, and idiot-friendly. If you're still stuck in the old carrot-and-stick, mediocrity-intolerant, primitive mentality, these recipes will open your eyes.

[image error]Dogville (2003) by Lars von Trier

Be Positive. You must remember that keeping people happy is more important than their results, effectiveness and...

 •  0 comments  •  flag
Share on Twitter
Published on June 05, 2017 17:00

May 29, 2017

Why Do You Contribute to Open Source?

You probably remember my half-a-year-old article: Why Don't You Contribute to Open Source?. I said there that if you don't have your own OSS projects or don't give anything back to those you're using—something is wrong with you. Now I'm talking to those who actually do contribute without demanding anything back—guys, you're doing it wrong!

[image error]The Untouchables (1987) by Brian De Palma

Open source almost always means free, as in beer—nobody will pay you a...

 •  0 comments  •  flag
Share on Twitter
Published on May 29, 2017 17:00

May 22, 2017

Any Program Has an Unlimited Number of Bugs

This may sound strange, but I will prove it: no matter how big or stable a piece of software is, it has an unlimited number of bugs not yet found. No matter how many of them we have already managed to find and fix, there are still too many left to count.

[image error]L'amico di famiglia (2006) by Paolo Sorrentino

Let's take this simple Java method that calculates a sum of two integers as an example:

int sum(int a, int b) { return a + b; }

This simple program has an unlimited number of bugs.

To pr...

 •  0 comments  •  flag
Share on Twitter
Published on May 22, 2017 17:00

May 16, 2017

Single Statement Unit Tests

Many articles and books have already been written about unit testing patterns and anti-patterns. I want to add one more recommendation which, I believe, can help us make our tests, and our production code, more object-oriented. Here it is: a test method must contain nothing but a single assert.

[image error]Bullet (1996) by Julien Temple

Look at this test method from RandomStreamTest from OpenJDK 8, created by Brian Goetz:

@Test public void testIntStream() { final long seed = System.currentTimeMilli...
1 like ·   •  0 comments  •  flag
Share on Twitter
Published on May 16, 2017 17:00

May 15, 2017

Monikers Instead of Variables

If we agree that all local variables must be final, multiple returns must be avoided, and temporal coupling between statements is evil—we can get rid of variables entirely and replace them with inline values and their monikers.

[image error]OSS 117: Cairo, Nest of Spies (2006) by Michel Hazanavicius

Here is the code from Section 5.10 (Algorithms) of my book Elegant Objects:

public class Main { public static void main(String... args) { final Secret secret = new Secret(); new Farewell( new Attempts(...
1 like ·   •  0 comments  •  flag
Share on Twitter
Published on May 15, 2017 17:00