Viktar Patotski Profile picture
Oracle Certified Java Developer. Tweets: Java, Linux, K8s, Cloud development and deployment, random topics. Stop global warming - write efficient code!
Mar 1, 2023 4 tweets 1 min read
The Shirky Principle

Institutions will try to preserve the problem to which they are the solution.

-- Clay Shirky
👇 The Shirky Principle suggests that complex solutions - a company, an industry, or a technology - can become so focused on the problem that they are solving, that they can inadvertently perpetuate the problem itself.
Mar 1, 2023 4 tweets 2 min read
⚠️#Spring tests tip

I wouldn't say I like @​Transactional spring tests and don't recommend using them. I prefer cleaning/populating db with @​Sql annotation. To do this I usually create 2 files:
📍resources/clear.sql
📍resources/insert_data.sql
👇 📍clear.sql usually contains:

TRUNCATE TABLE table1, table2 RESTART IDENTITY CASCADE;

This script deletes all data from DB but leaves a structure.

📍insert_data.sql

This script populates data by executing Inserts.
Feb 28, 2023 6 tweets 2 min read
Learning #Java is a never-ending story for me: I just learned about " double-brace initialization", which creates an anonymous class derived from the specified class (the outer braces), and provides an initialiser block within that class (the inner braces). e.g. 👇 For example, this code:
List<Integer> l = new ArrayList<>();
l.add(1);
l.add(2);

May look like:
new ArrayList<Integer>() {{
add(1);
add(2);
}};
Feb 27, 2023 5 tweets 1 min read
The Pareto Principle (The 80/20 Rule)

Most things in life are not distributed evenly.

The Pareto Principle suggests that in some cases, the majority of results come from a minority of inputs: 👇 📍80% of a certain piece of software can be written in 20% of the total allocated time (conversely, the hardest 20% of the code takes 80% of the time)
📍20% of the effort produces 80% of the result
📍20% of the work creates 80% of the revenue
Feb 26, 2023 4 tweets 2 min read
The Dilbert Principle

Companies tend to systematically promote incompetent employees to management to get them out of the workflow.

-- Scott Adams

en.wikipedia.org/wiki/Dilbert_p… A management concept developed by Scott Adams (creator of the Dilbert comic strip), the Dilbert Principle is inspired by The Peter Principle.
Feb 26, 2023 4 tweets 2 min read
#Java performance comparison.

Today I decided to check the performance of different ways of converting an int variable to a String object in Java. 🧵👇 I searched on Stackoverflow:
📍Integer.toString(i)
📍"" +i
📍String.valueOf(i)
📍new StringBuilder().append(i).toString() - a bit strange way, but it was one of the suggestions😄

I have implemented 4 benchmarks using the JMH framework (see pictures).

Results 👇
Feb 25, 2023 5 tweets 1 min read
The Dead Sea Effect

The more talented and effective IT engineers are the ones most likely to leave - to evaporate ... [those who tend to] remain behind [are] the 'residue' — the least talented and effective IT engineers. 🤓

--Bruce F. Webster The "Dead Sea Effect" suggests that in any organisation, the skills/talent/efficacy of engineers is often inversely proportional to their time in the company.

Typically, highly skilled engineers find it easy to gain employment elsewhere and are the first to do so.
Feb 18, 2023 6 tweets 3 min read
⚠️#Java performance comparison⚠️

I decided to compare the performance of different collection iteration options. In particular:
📍 for loop
📍enhanced for loop
📍for loop with an Iterator
📍stream

Details🧵👇 To test it, I have implemented 4 Benchmark methods, each iterating through list of positive integers and checking them for equality to -1. And at the end of the method, it returns 0 since non was found. In short: Just iterating through the entire collection.
Feb 17, 2023 7 tweets 4 min read
⚠️Top 5 Trending Java GitHub repositories February 2023⚠️
(Android excluded)

🧵👇 1️⃣ OpenAI-Java - Java libraries for using OpenAI's GPT-3 api.
Includes:
api - request/response POJOs for the GPT-3 APIs
client - retrofit client for the GPT-3 endpoints
service - service class that creates and calls the client

by @TheoKanning
github.com/TheoKanning/op…
Feb 11, 2023 8 tweets 3 min read
⚠️#Java performance tip⚠️
Use primitive types instead of wrappers.

Java primitive types:
📍byte
📍short
📍int
📍long
📍float
📍double
📍char
📍boolean

More details and explanation in 🧵👇 To show the difference in performance between primitive and wrapper objects I have created a benchmark which just creates an array of "int" and "Integer" and fills them with an index. Sizes of array: "10", "100", "1000", "10000"

Results: 👇
Feb 10, 2023 4 tweets 1 min read
The Scout Rule

Always leave the code better than you found it.

-- (Robert C. Martin (Uncle Bob)) Based on the "Scout Rule", which is "always leave the campground cleaner than you found it", the Scout Rule in programming is simply "always leave the code cleaner than you found it".

This was introduced in the first chapter of the book Clean Code by Bob Martin.
Feb 8, 2023 6 tweets 2 min read
The Law of Triviality

This law suggests that groups will give far more time and attention to trivial or cosmetic issues rather than serious and substantial ones. The common fictional example used is that of a committee approving plans for nuclear power plant, who spend the majority of their time discussing the structure of the bike shed, rather than the far more important design for the power plant itself.
Feb 4, 2023 11 tweets 3 min read
⚠️#Java performance tip⚠️

Don't use "+" for string concatenation. Use StringBuilder or StringBuffer instead.
I have created a benchmark to compare the speed of StringBuilder, StringBuffer and "+" concatenation for 2, 3, 5, 10, 50, and 100 strings.
Details in 🧵👇 The scenario is simple:
s/sb = ""/new StringBuffer/Builder();
for (int i = 0; i < size; i++) {
s+=i;/sb.append(i);
}
return sb.toString();

size = 2, 3, 5, 10, 50, and 100

Size hundred produced super strange result, which I can't explain yet. 😕
Feb 2, 2023 10 tweets 3 min read
#Java performance Tip: `parallelStream()` is way slower than regular `stream()` on small amount of data. I have created a simple benchmark and run it on my 8-CPU laptop. The difference is 160x for some cases. 😲

Details 🧵 👇 👷The setup is to run the same code for streams of 10, 1000, 10_000, 100_000, and 1000_000 items long in standard and parallel modes:
list.stream()
.filter(i -> i == -1)
.findAny()
.orElse(0);
Feb 1, 2023 7 tweets 3 min read
The Law of Leaky Abstractions

"All non-trivial abstractions, to some degree, are leaky."

by @spolsky

joelonsoftware.com/2002/11/11/the… @spolsky This law states that abstractions, which are generally used in computing to simplify working with complicated systems, will in certain situations 'leak' elements of the underlying system, this making the abstraction behave in an unexpected way.
Jan 31, 2023 6 tweets 2 min read
#Java performance Tip: When need to copy items from one array to anoyther one, don't use loops. Use the more efficient Arrays.copyOf or System.arraycopy method instead.

Performance test details in 🧵👇 Given:
☕ int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};

❌ int[] arr2 = new int[30];
for (int i = 0; i < arr.length; i++) {
arr2[i] = arr[i];
}
Jan 12, 2023 18 tweets 4 min read
⚠️Thread alert! ⚠️
Relational databases are still the most popular data storage for various projects. Here are some tips on how to scale relational databases to support more throughput, serve more clients, or get faster query processing. 🧵: 1. Update the version
Newer versions of traditional SQL databases typically come with performance improvements. Even if the newer database system is not faster as a direct replacement, there might be new features available that we can take advantage of.
Jan 10, 2023 12 tweets 2 min read
Functional correctness of software is essential, but Non-Functional Requirements (NFRs) are usually forgotten during development. Here are the top 10 crucial NFRs you should care about 🧵 👇 1. Performance
Focuses on the system's speed, efficiency, and workload. It covers how fast the system should process requests and respond to them.
Jan 4, 2023 6 tweets 2 min read
👮🏼‍♀️ FBI: "Cyber Criminals Impersonating Brands Using Search Engine Advertisement Services to Defraud Users"

The FBI recommends individuals take the following precautions: 🧵👇 📍Before clicking on an advertisement, check the URL to make sure the site is authentic. A malicious domain name may be similar to the intended URL but with typos or a misplaced letter.
Jan 3, 2023 8 tweets 5 min read
Top 6 free @intellijidea plugins you don't want to miss. 🧵 👇 Key Promoter X - The Key Promoter X helps you learn essential shortcuts while working. When you use the mouse on a button inside the IDE, the Key Promoter X shows you the keyboard shortcut you should have used instead.

Absolute Must❗
👉 rli.to/UDW0z
Dec 20, 2022 13 tweets 6 min read
Hey #JVM folks, are you willing to explore some Deep Machine Learning or AI and not ready to learn Python? I have collected a list of libraries which allow you to implement any ML dreams without leaving the #JVM world. 🧵 👇 deeplearning4j - a suite of tools for deploying and training DL models using the JVM. Highlights include model import for keras, tensorflow, and onnx/pytorch, a modular and tiny c++ library for running math code.

100% must see 👉 rli.to/iNTuA