Brain friendly programming in Java

We have many principles for writing better more maintainable software, but still end up with a tangled mess.

Most of us have heard about the Single Responsibility Principle (SRP), Robert C Martin expressed this principle as “A class should have only one reason to change”.

He later clarified this by stating “Gather together the things that change for the same reasons. Separate those things that change for different reasons”.

We also have the Single Layer of Abstraction Principle (SLAP) which is expressed as “Don’t mix levels of abstractions”.

Dan Terhorst-North presented his Unix Philosophy as “does one thing well”.

The goal is to create more maintainable software, not to fulfill the principle. It’s still possible to create a mess even though we follow all the SOLID principles. So what do these principles mean, and how can I as a developer use them to create better software?

The Science Behind Brain-Friendly Programming Methods

In “The Programmer’s Brain“, Dr. Felienne Hermans talks about how our brain works working with code.  It’s a highly recommended read.

One of the key takeaways for me was the fact that our working memory can only keep track of 3 – 5 chunks of information at the same time. How big a chunk is depends on how much experience we have with the current task.

It can be individual statements, lines, or entire design patterns.

We can make our code easier to understand, to lower the cognitive load of the reader, by limiting the number of chunks of information we have to keep track of.

Ok, so how do we do that then?

Cognitive Load: Minimizing Mental Strain for Optimal Programming Performance

This is when the presentation “Simple Made Easy” from Rich Hickey, comes in.

He talks about how we complect our code.

Complect is an old word that means to braid together, to weave together. By completing our code we make it harder to understand by requiring the reader to keep more chunks of information in memory. We are increasing the cognitive load for the reader.

He suggests that we should separate our code based on the following questions:

  • What needs to be done?
  • Who wants to do it?
  • How should it be done?
  • When should it be done?
  • Where should it be done?
  • Why should it be done?

By mixing these, complecting them, we create code that is harder to understand because it requires the reader to keep more chunks in memory, which creates a higher cognitive load.

By keeping these separate, we get code that is easier to change and reuse, for instance, we can then change how something is done without affecting who wants it done.

Another thing we can do to make our code easier to understand is to take advantage of new features in the language we are using.

We often hear that we should update to the latest version of our language for performance and security reasons. But there are also improvements in the language that can make our code easier to understand.

Let’s take Java as an example.

Leveraging New Java Language Features to Lower the Cognitive Load of the Programmer

Java, being one of the most popular programming languages in the world, is constantly evolving to meet the changing demands of software development. With each iteration, Java introduces new language features that not only enhance the performance and scalability of applications but also aim to make the lives of programmers easier.

I’ll list a few of the new Java language features that, when used, can lower the cognitive load of programmers, allowing us to write more efficient and maintainable code.

Concise Code with Lambda Expressions

Lambda expressions, introduced in Java 8, allow developers to write more concise code by expressing instances of anonymous functions. By using lambda expressions, programmers can reduce boilerplate code and focus on the core logic of their applications. This feature is a good match for handling collections, stream processing, and event handling. For example, instead of writing lengthy loops to iterate over a list, lambda expressions can be used to achieve the same result in a more compact and readable manner.

Improved Null Safety with Optional

Java 8 introduced the Optional class, which helps handle null values more effectively. By using Optional, programmers can avoid NullPointerExceptions and write safer code. Optional encourages developers to handle null values explicitly, leading to more robust and error-free applications. This feature reduces the cognitive load of programmers by providing a clear and standardized way to deal with null values, making the code more predictable and easier to reason about.

Enhanced Pattern Matching

Java 14 introduced pattern matching for instanceof and this has been extended and improved on in newer versions since then. This feature simplifies the code by combining type checking and type casting into a single operation. Programmers can write cleaner and more concise code when working with complex data structures by using pattern matching. Pattern matching reduces the cognitive load of programmers by eliminating the need for if-else blocks and switch statements, leading to more readable and maintainable code.

Simplified Asynchronous Programming with CompletableFuture

Asynchronous programming is essential for building responsive and scalable applications. Java 8 introduced the CompletableFuture class, which makes asynchronous programming simpler by providing a convenient way to work with future values. Programmers can chain asynchronous operations and handle their results more intuitively using CompletableFuture. This feature reduces the cognitive load of developers by abstracting the complexity of asynchronous programming and allowing them to focus on the business logic of their applications.

The evolution of Java language features has brought significant improvements to the way programmers write and maintain code. By leveraging features such as lambda expressions, Optional, pattern matching, and CompletableFuture, developers can lower the cognitive load associated with programming tasks. These features enable programmers to write more concise, robust, and maintainable code, ultimately leading to increased productivity and efficiency in software development. 

As Java continues to evolve, developers can expect more innovations to enhance their programming experience further and make Java an even more powerful and developer-friendly language.

Conclusion

By understanding how the brain processes information, developers can create programming languages and environments that are more intuitive, efficient, and less cognitively demanding for users. This approach can improve the overall user experience, increase productivity, and promote greater accessibility for individuals of all cognitive abilities.

Embracing brain-friendly programming will not only benefit individual programmers and users but has the potential to revolutionize the way we interact with technology and shape the future of computing.

Mastering the Craft: 7 Habits of Highly Effective Developers

Physical training

Physical training, also known as exercise or fitness training, is crucial to maintain a healthy lifestyle and improve overall well-being. It involves engaging in planned physical activities targeting specific muscle groups, enhancing cardiovascular endurance, improving flexibility, and building strength.

Besides the physical benefits, exercise positively impacts mental and emotional well-being. Physical training stimulates the release of endorphins, often called the “feel-good” hormones. These neurotransmitters alleviate stress, anxiety, and depression, promoting a positive mood and overall mental well-being.

Exercise is proven to enhance cognitive abilities, memory, and concentration.

Sharing

As a software developer, you possess a wealth of knowledge and experiences that can benefit others in the field.

Sharing your knowledge helps others, but it will also showcase your expertise and solidify your position as an authoritative figure in the software development community. Teaching is the best form of learning. Try keeping a log of problems you have encountered and how you solved them. You will likely have similar issues in the future. You can also use it to find interesting topics to share.

Why not present something you have learned to your company or at a conference? I know it can be scary, but it’s also rewarding. It will help you grow as a developer.

Automate

Automation has become an essential aspect of the developers’ toolkit, especially with the increasing complexity of software development projects and the need for faster delivery. Automating repetitive tasks and processes saves time, improves efficiency, minimizes errors, and enhances productivity.

We will be more productive and can stay in the flow when writing code if we learn the keyboard shortcuts in the IDE rather than switching to the mouse.

A good way is to learn the shortcuts for the operations we do the most. For instance, how do I quickly jump between code and tests? How do I rename something?

We should not be afraid of using the command line to perform actions if it’s more effective.

Focus

Our ability to focus and efficiently manage our tasks is crucial to the success of any project. However, one of the biggest obstacles to achieving this focus is the constant context-switching we have to deal with. Moving from one task to another is referred to as context switching. These switches may happen due to changing priorities, interruptions from colleagues or stakeholders, or simply because we work on multiple features simultaneously.

We should minimize its impact on productivity and mental well-being, even if context switching might appear unavoidable in this fast-paced industry.

Turning off all social media and emails made it easier for me to focus. I put the editor in full screen when I code and try to use as many keyboard shortcuts as possible to avoid switching between keyboard and mouse.

A quiet and organized space promotes better focus. If there’s noise, investing in noise-canceling headphones could be worthwhile.

Reflect

Reflection is an essential and powerful practice that every software developer must embrace to reach new heights of success and excellence in their field. Developers can truly become indispensable team members by investing time and effort into thoroughly reviewing their work, analyzing mistakes, honing problem-solving abilities, elevating code quality, boosting efficiency, fostering professional growth, and nurturing collaboration. The act of reflection not only accelerates individual growth but also plays a pivotal role in driving the overall triumph of software development projects.

Journaling is a valuable practice that will undoubtedly enhance your daily life. By diligently documenting your experiences, you invite introspection and self-reflection and create a sense of closure at the end of each day. This journaling ritual enables you to release any lingering thoughts or emotions, granting you the freedom to unwind and detach from the events that transpired throughout the day.

Empathy

Empathy is the ability to understand and share the feelings of another person. It involves putting yourself in someone else shoes, considering their perspective, and acknowledging their emotions. Empathy fosters better communication and stronger relationships in a collaborative work environment. It enables teams to work more effectively together. You can find more information about this in a guest post I wrote here: https://digma.ai/blog/the-empathetic-developer/

Simplify

Code is not merely a tool for businesses; it is an essential component that directly impacts the behavior and value of software systems. Good code ensures efficiency, reliability, and maintainability. Poor quality code leads to increased costs and decreased value creation. By prioritizing code quality, businesses can avoid the pitfalls of technical debt, deliver faster and more stable systems, and achieve a competitive advantage in the market. Code is cost, and behavior is value – an equation that every business should strive to balance.

We should aim to provide comments that explain the reasoning behind the design of the code rather than just describing its functionality. Do not comment to cover up poor-quality code. We should program with intent. One way to help us with this is to apply the four rules for simple design by Kent Beck. It passes all the tests. It reveals intention. It avoids duplication and utilizes the fewest possible elements in its construction.

A good code should read like a story, not like a puzzle. William Zinsser describes his principle on writing in his book On Writing Well. We can create better results by focusing on simplicity, clarity, brevity, and humanity. Write programs for people to read and occasionally for machines to execute.

Review often to get feedback to avoid turning it into a blessing. Say what can be improved, not what is wrong.

The Power of Small Habits: Utilising Atomic Habits to Develop Your Team’s Skills

Small habits have significant power in our lives and work. Habits we develop over time can either make or break us, and the same goes for the results we achieve with our team. As a leader or manager, one responsibility is to foster the development of your team’s skills by motivating them and promoting positive habits.

This is where the concept of atomic habits comes in. Atomic habits are tiny modifications that are simple to adopt and stick to, yet they can have a significant impact on the outcome. By adopting atomic habits, you can develop your team’s skills gradually and consistently, resulting in significant growth, improved performance, and ultimately success.

In this article, we will explore the concept of atomic habits and how you can utilize them to develop your team’s skills. We will discuss the benefits of adopting atomic habits, the different types, and practical tips for effectively implementing them. After reading this article, you’ll know how to use small habits to improve your team’s skills and achieve more success.

Introduction to Atomic Habits: Understanding the Power of Small Changes for a Learning Mindset

Atomic Habits, a book written by James Clear, is a revolutionary guide to understanding how small changes in our daily habits can compound over time and lead to significant improvements in our lives. By mastering the art of creating and maintaining atomic habits, one can develop a learning mindset that will help them achieve their goals, whether they are personal or professional.

According to Clear, behaviour change is driven by four fundamental laws that influence our actions:

Cue – The initial trigger that signals our brain to begin a specific behavior.

Craving – The desire or craving that motivates us to take action and seek a reward.

Response – The actual behavior or action we take in response to a cue and craving.

Reward – The positive outcome that reinforces our behavior and satisfies our craving.

By understanding these four laws, we can create atomic habits that work in our favor rather than against us. For example, if we want to develop a habit of writing more maintainable code:

Cue – Create an environment that promotes maintainable code.

Craving – A desire to write maintainable code.

Response – Implement maintainable coding practices.

Reward – A sense of accomplishment for writing maintainable code.

The Importance of Small Wins

One of the key principles of Atomic Habits is the importance of making small, incremental improvements. Rather than trying to overhaul our entire lives overnight, we should focus on making small, sustainable changes that will compound over time.

Clear argues that the most significant changes in our lives come from the compound effect of small wins. For example, if we want to write maintainable code, we can focus on using meaningful variable names or avoid hard-coding values.

These small wins, when repeated consistently, can lead to significant improvements in the maintainability of the code over time. If you can get 1% better each day, you’ll end up with results that are up to 37 times better after just one year.

The Learning Mindset

Developing atomic habits is not just about achieving individual goals but about developing a learning mindset that will help us adapt and thrive in a constantly changing world. By focusing on small improvements and learning from our failures, we can build resilience and become better equipped to succeed in the face of adversity.

Clear argues that the key to developing a learning mindset is to focus on identity-based habits rather than outcome-based habits. Rather than focusing on achieving a specific outcome (writing maintainable code), we should focus on developing habits that align with our desired identity (such as becoming a sought-after expert in the software industry).

Identifying Current Habits: Assessing Your Software Development Team’s Learning Habits

As a software development team lead, identifying the current habits of your team is crucial to ensure continuous learning and development. By analyzing learning needs, evaluating current learning methods, identifying learning styles, tracking progress, providing regular training opportunities, and encouraging collaboration and communication, you can create an environment where learning becomes a natural and ongoing process. This will benefit both your team and your business by enhancing the quality of your software products and services.

Setting Clear Goals: Fostering Motivation and Direction for Individual and Team Development

Setting clear goals is an essential aspect of personal and professional development. It gives direction, focus, and motivation for individuals. Without clearly defined goals, people often lack direction and purpose, which can lead to a lack of motivation and poor performance.

Setting clear goals is essential for personal and professional development. It gives individuals and teams the direction and motivation needed to achieve their desired outcomes. Remember to set SMART goals, break them down into smaller targets, develop an action plan, and monitor progress to ensure success. With clear goals, you can achieve your dreams and aspirations!

Breaking Down Learning Goals: Creating Manageable Steps for Consistent Progress

Learning goals are what learners hope to achieve as a result of undertaking a particular learning process. These goals are essential for several reasons. Firstly, they provide guidance and focus, making it easier for learners to stay on track; secondly, learning goals enable learners to assess their progress more objectively and make adjustments where necessary. Thirdly, learning goals can help to motivate learners and boost their confidence.

Additionally, learning goals are vital because they help learners to see the bigger picture, even when studying complex subjects. When set up correctly, learning goals can shape the way students prioritize their time and resources. By breaking down goals into smaller and more manageable steps, students can manage their time and avoid feeling overwhelmed when attempting to tackle any project head-on.

Tracking Progress: Using Metrics and Data to Measure and Celebrate Small Wins

Tracking progress is an essential part of successful goal setting. However, measuring progress requires more than just setting objectives and tracking numbers. It involves establishing clear metrics and data to measure results, identifying potential barriers, and celebrating small wins.

Metrics are your tools for measuring progress. You must identify your most significant objectives, set clear goals, and determine how to measure the results. For example, if the goal is to increase website traffic, you might track metrics like sessions, bounce rates, and click-through rates. By focusing on specific metrics, you can accurately gauge your progress and make data-driven decisions to improve your performance.

It’s essential to identify potential barriers that can hinder your progress. These barriers may be internal or external factors such as lack of resources, lack of skills or knowledge, or market changes. Once you identify these barriers, you can create a plan to overcome them.

One way to identify potential barriers is to conduct a SWOT analysis, Strengths, Weaknesses, Opportunities, and Threats. A SWOT analysis can help you identify areas where you need to improve and give you a better understanding of your competitive landscape.

Monitoring progress is crucial because it allows you to measure the effectiveness of your efforts. Without monitoring, you won’t know if you’re making progress or not. Monitoring can also help you identify areas where you need to change your strategy.

People tend to focus on the big wins, but celebrating small wins can be just as important. Celebrating small accomplishments along the way can help you stay motivated and engaged.

When celebrating small wins, make sure to recognize the effort, not just the result.

Small wins provide positive reinforcement that can help you sustain your efforts toward achieving your bigger goals. Celebrating small wins can also help to create a culture of recognition within your team.

Creating a Positive Learning Environment: Encouraging Collaboration and Open Communication

One of the key elements of creating a positive learning environment is creating a culture that values collaboration and teamwork. When people feel that their opinions are valued, and they feel supported by their peers, they are more likely to participate actively in discussions and activities. Collaboration fosters a sense of community in the team and promotes positive relationships between members, leading to better communication and improved learning outcomes.

Creating a positive learning environment also involves using positive reinforcement. Recognizing and celebrating team members’ efforts and achievements, and providing them with constructive feedback on their growth, motivates them to strive for excellence. Leaders should avoid negative reinforcement, such as punishments, which can reduce team members’ confidence and discourage them from participating fully in activities.

Finally, it is vital to establish clear guidelines and expectations for behavior and conduct. Leaders should create rules and enforce them consistently, ensuring that all team members fully understand what is expected of them. The guidelines should promote respect, inclusivity, and responsibility for individual and collective learning outcomes.

Building Feedback Loops: Leveraging Feedback to Continuously Improve Habits and Skills

Human beings are born with the innate desire to improve themselves. Whether it’s learning a new skill, improving existing habits, or achieving a personal goal, people are constantly striving to make themselves better. However, improving oneself is not always an easy task. Often, people lack the knowledge, motivation, and discipline to stick to the changes they seek. This is where feedback loops become vital.

Feedback loops are an effective way of continuously improving habits and skills. They help individuals track their progress, identify areas that need improvement, and make necessary adjustments. Building feedback loops is not rocket science. It’s a simple process that involves setting clear goals, gathering relevant data, analyzing it, and making necessary adjustments. By incorporating feedback loops into your daily routines, you’ll be amazed at how much progress you can achieve toward your goals.

Adopting a Growth Mindset: Embracing Challenges and Learning from Failures

When it comes to personal development and achieving our goals, the way we approach challenges and failures can significantly impact our success. Some people have a fixed mindset, believing that their abilities and qualities are predetermined and cannot be changed. Others have a growth mindset, perceiving challenges and setbacks as opportunities for learning, improvement, and new experiences.

Adopting a growth mindset can be a powerful tool for personal growth, success, and fulfilment. By reframing challenges as opportunities, learning from failures and setbacks, focusing on the process, and surrounding yourself with growth-oriented people, you can develop a more positive and proactive outlook on life. Remember, growth is a lifelong journey, and there’s always room for improvement and learning. So embrace challenges, take risks, and never stop growing.

Developing Resilience: Staying Committed to Learning Habits Through Setbacks and Obstacles

Learning is a lifelong process. No matter how old we are, there is always something new to learn. Whether you’re a student, a working professional, or simply someone who wants to enhance your knowledge, learning takes commitment and resilience. It requires dedication and constant effort to develop skills and acquire new knowledge. But what happens when setbacks and obstacles come your way, and you feel like giving up? This is where resilience comes in.

Resilience is the ability to bounce back from setbacks, overcome challenges and persevere when faced with obstacles. It’s a key trait that helps us push through difficult times and continue to progress in our learning journey.

Developing resilience is essential for staying committed to your learning habits through setbacks and obstacles. By reframing setbacks as opportunities for growth, setting realistic goals, practicing self-care, seeking support when needed, embracing failure, and staying flexible and adaptable, you can maintain a positive attitude and continue to make progress in your learning journey. Remember, learning is a process, not a destination, so stay committed and stay resilient!

Maintaining Consistency: Making Learning a Sustainable Habit for Your Software Development Team

In the fast-paced world of software development, it is essential to keep up with the latest technologies and trends. This requires a team that is constantly learning and adapting to new changes.

To ensure that your software development team continues to learn and grow, you need to make learning a sustainable habit.

This requires creating a culture that supports continuous learning and provides the necessary resources and opportunities. As a team leader, you need to set an example, provide resources, integrate learning into the workflow, celebrate success, measure progress, and provide feedback. By doing this, you can ensure that your software development team remains agile, adaptive, and relevant in the ever-changing world of technology.

To learn more about Atomic Habits, visit: https://jamesclear.com