Why Classical Singleton Is an Antipattern: How To Make It Great Again Using IOC

Classical Singleton Introduction

Classical Singleton is one of the most well-known structural patterns. It is widely used in production and is responsible for creating only one single instance. This pattern was mentioned in the GOF patterns book. How is it possible that it became an antipattern? Before we start, let's remember what a classical Singleton looks like.  

Classical Singleton Implementation

Classical implementation of Singleton assumes that class contains two things:

Keith Jarrett’s Agile Craftsmanship

Many non-technical skills, qualities, and mindsets are part of software craftsmanship. Today I want to talk about two: 

  • Resilience 
  • Improvisation

Resilience helps us cope with difficulties by not giving up too soon. Improvisation deals with compromise and creativity in the face of the unexpected. The intuition to distinguish negotiable best practices from unchangeable truths is what agility is about. In earlier posts, I drew analogies between people from art and fiction (Stanley Kubrick, Woody Allen, and Gomer Goof). 

Design Insights From Unit Testing

Probably the biggest breakthrough while Unit Testing is to realize that writing tests offer priceless feedback about the design of your production code. This feedback goes from suggesting immediate obvious improvements, up to hints about some of the most advanced design principles in software engineering. This article briefly enumerates these hints, pointing to questions to ask about your design. 

Disclaimer: Don't follow blindly these hints, but make sure you understand all of them so that you can decide in your real problem what would improve the design, and what wouldn't.

10 Must-Know Patterns for Writing Clean Code With React and Typescript

Introduction 

React is a JavaScript library, and it is the most popular and industry-leading frontend development library today. JavaScript is a loosely typed language, and as a result, it catches runtime. The result of this is that JavaScript errors are caught very late and this can lead to nasty bugs. As a JavaScript library, React inherits this problem.

Clean code is a consistent style of programming that makes your code easier to write, read, and maintain. Anyone can write code that a computer can understand but good developers write clean code – code that humans can understand. Clean code is a reader-focused development style that improves our software quality and maintainability.

Things We Still Do, Twenty Years Onward

Joel Spolsky’s once prolific blogging output dried up years ago, but Things You Should Never Do, Part I is still a classic after 22 years. He wrote it as an outsider’s postmortem following the first beta release (6) of Netscape’s browser, three years after the previous major release 4. There never was a version 5. The team had decided on a full rewrite, and the resulting delay probably cost them their competitive advantage over Microsoft’s Internet Explorer. 

If Netscape actually had some adult supervision with software industry experience, they might not have shot themselves in the foot so badly”, he closes. 

Protect Your Invariants!

How do you handle constraints and validation inside your application? Most developers put this logic somewhere close to their application's boundary. Actually, this prevents them from having a rich domain model that could ensure consistency.

Developers tend to get confused when they need to find a good place for their business logic. I suspect that most probably the reasons are related to all those bad examples circulating in the documentations of popular frameworks and bad habits from coding in old-fashioned enterprise platforms like J2EE. Most of the time, they're afraid to keep these vital pieces of information in the language elements most relevant to the target domain: I'm talking about the simple classes reflecting the "nouns" of the business logic. Often, you see something like the example below:

Documenting the Architecture of Your Projects With the C4 Model

One of the definitions used to approach software architecture is that it is responsible for defining the parts of a project and the technological strategy. And, like any strategy, there must be an ongoing process of review and update. That's why, here on the Zup Open Source team, we're using the C4 model.

Having a view of your project's architecture is crucial in several aspects, as it helps you answer questions such as: how can my system integrate internally or with other systems? Or, how can I guarantee security between my applications? And so on.

Writing Clean Code: Naming

When you start learning how to code your main focus is writing code that works correctly for the problem you are solving. Yes, code needs to work correctly and that is a good place to start learning. However, in a real work environment, you also want to ensure you write clean code.

Clean code is readable, extensible, changeable, and maintainable. These are all important qualities for a code to have.

The Woody Allen Way of Coding

In a previous post I wrote about the uncompromising artistry of Stanley Kubrick, who produced film classics at the cost of wildly unpredictable schedules and budgets. You can reach for similar brilliance in programming, but you had better do it on your own time or with a generous CFO. There is a different, more workable, and healthier attitude towards our craft. Just keep at it, enjoy it, and don’t worry about making a dent in the universe. I'm reading Woody Allen’s autobiography over the holidays, so indulge me to draw another cinematic parallel with this veteran New York writer/director. Don’t worry, it will also be about coding.

Woody Allen is one of the most consistently prolific cinematographers in the business. He has written and directed over fifty films over an equal number of years, almost like clockwork. At 85 he has no intention of stopping. He doesn’t approach his oeuvre as a project with a culmination. His business is about keeping busy. He is in it for the long run, if only to act as an antidote to the unavoidable spectre of death and oblivion. But let’s not get into his glum outlook on the meaning of life.

How to Save Time While Debugging

In this article from our small series for junior developers, we will focus on how to save time while debugging and what are the best practices of senior developers when fixing the errors.

The Stripe’s study from 2018 says that developers spend over 41% of their time on maintaining and debugging the code. Imagine, out of 20 working days in a month, a week and a half of time does not add value to the business. Let us give you some advice on how to lower this large chunk of time that could be spent on creating new features.

Your Simple Coding Guide: Functions and Methods

What makes a good function or method? It's not just one thing, but rather a combination of things where each is significant. If something is flawed, it affects the whole function. So what are these common slip-ups, and how can you avoid them?

It Has a Meaningful Name

Functions should have names that describes their purpose or functionality. When a function has a meaningful name, it's easy to read and understand its purpose.

For example, if a function's purpose is to find a customer by ID, a good name could be findCustomerById(id: String). It could also just as well be findCustomer(id: String) because the function signature implies that the customer is found by their ID. The word find also implies that the customer might be found or it might not be found.

If the function's name would be changed to getCustomer(id: String), its meaning changes because now it implies that there's no fallback; the customer is either found or the function fails miserably and maybe throws an exception.

Both are valid names for a function but they have a different meaning and therefore their implementations should also be different.

React Clean Code

Clean code is more than just working code. Clean code is easy to read, simple to understand, and neatly organized. In this article, we’ll look at eight ways we can write cleaner React code.

When going through these suggestions, it’s important to remember that’s exactly what they are: suggestions. If you disagree with any of them, that’s completely fine. However, these are practices that I’ve found helpful in writing my own React code.

A Case Study on Spring Framework

The Spring Framework is a great application framework and inversion of control container for the Java platform. It is also a great example of high-quality software. Spring Framework is the foundation for all Spring projects. Collectively, the Spring Framework and the family of Spring projects is often referred to simply as "Spring." Spring provides everything required beyond the Java programming language for creating enterprise applications for a wide range of scenarios and architectures. It has been developed over 17 years.

We analyzed the Spring Framework with CodeMR. CodeMR is an architectural software quality and static code analysis tool. You can find  analysis report generated with CodeMR at: https://www.codemr.co.uk/case-reports/spring-framework/html/html_report_spring-core/htmlx/lbd/dashboard.html.

How Readable Is Your Code? Part 2

Once Again About Cyclomatic Complexity

In the first part, I've introduced Cyclomatic Complexity (CYC) metrics in the previous part. So CYC has no intention to be a readability code metric. CYC was invented a long time ago (in 1976)  by Thomas J. McCabe. 

Cognitive Complexity Metric.

Cognitive Complexity (CC) attempts to count the cognitive effort required to understand the code's flow. Let's take a look at the next example:

How Readable Is Your Code? Part 1

There Is No Perfect Implementation?

Every developer has his own preferences and vision about problem-solving. Any problem can be solved in my différent ways following know practices like SOLID, KISS, etc. But how to compare 2 different implementations? Smaller is better? Only Object-Oriented? How practically evaluate notions like code maintainability, readability, transparency? Well, I'm not sure that there is absolute truth in such questions, but in this article, you will find a metric that can help you find out. 

Cyclomatic Complexity — Number of Scenarios in Code.

Cyclomatic complexity is a metric invented to find out the number of tests to cover the given code fully. This metric also can be used to measure the readability of your code.  Cyclomatic Complexity shows how many scenarios consist of your code (or how many independent ways inside its graph)

6 Tips to Help You Write Cleaner Code in Node.js

Node.js is one of the most popular lightweight JavaScript frameworks that allow you to create powerful server-side and client-side applications. As with any other language, developers must write clean Node.js code to get the most out of this application runtime environment.

Otherwise, your team will spend too much time juggling through blocks of unreadable code with unclear variable definitions, messy syntax, and duplicate functions. This can cause too much pain, especially when a developer is tasked with maintaining someone else’s code while pushing to meet deadlines.