Thought For The Day

“Languages are true analytical methods.”

Antoine Lavoisier

 

C++ Programming: Design Patterns and Suggestions 2/2

In the previous article we have talked about some general suggestions for programming using the object-oriented paradigm.  It is imperative to make your code easily modifiable, robust and modularized.  This enables reuse and, especially ragarding large projects, easier team work.  We have mentioned design patterns - a set of rules and suggestions which help the programmer write well organized code.  Now we will discuss different groups of design patterns, and give examples for some of them.

We have learned last time that, most commonly, design patterns are grouped like this: creational, structural, behavioral and concurrency patterns.  Let's see the classification of some common design patterns:

Single Responsibility Principle
  • Creational patterns
    • Abstract factory
    • Lazy initialization
    • Object pool
    • Singleton
  • Structural patterns
    • Bridge
    • Composit
    • Marker
    • Module
    • Proxy
  • Behavioral patterns
    • Chain of responsibility
    • Iterator
    • Null object
    • Single responsibility principle
    • Liskov substitution principle
  • Concurrency patterns
    • Blockchain
    • Join
    • Lock
    • Scheduler
    • Thread pool

 

Now, let's talk about some of the most commonly used patterns mentioned above.  The object pool pattern is a creational design pattern that uses a set of initialized objects kept ready to use - a "pool" - rather than allocating and destroying them on demand.  A client of the pool will request an object from the pool and perform operations on the returned object.  When the client has finished, it returns the object to the pool rather than destroying it; this can be done manually or automatically.  In some situations this approach significantly improves performance, but care is required with implementation, because the object lifetime is slightly more complicated then in a regularly created object.

Another creational pattern, the singleton pattern, restricts the instantiation of a class to only one object.  This can be useful when only one object is neeeded to perform administrative or coordination tasks.  This pattern can be implemented by declaring all constructors of the class to be private, or providing a static method that returns a reference to the instance.

Proceeding to structural patterns, the bridge pattern is a design pattern used in software engineering which is meant to "decouple an abstraction from its implementation so that the two can vary independently".  The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes.

Among the largest group - the behavioral patterns - one of the most interesting patterns is the single responsibility principle.  The single responsibility principle revolves around the claim that a certain code module (most often, a class) should only have responsibility over one part of the functionality provided by the software.  In software engineering books, this is sometimes also defined like this: the module should only have one reason to change.  This means that a division of concerns is performed in the program, and the methods for every concern should be completely encapsulated by a single class.

The Liskov substitution principle states the following: "in a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e., objects of type S may substitute objects of type T) without altering any of the desirable properties of that program (correctness, task performed, etc.)".  Simply said, any object of some class in an object-oriented program can be replaced by an object of a child class.

Finally, we will say something about the, probably, most important concept in concurrent programming - locking. In computer science, a lock or mutex (from mutual exclusion) is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution.  A lock is designed to enforce a mutual exclusion concurrency control policy.  Locks prevent multiple threads from accessing a shared variable, and changing its value in such a way that the correctness is compromised.  There are many different implementations of locks, including mutexes and semaphores.

3 of the Biggest Career Mistakes You Can Make

Sometimes in retrospect, we look back and can identify some big mistakes we've made along the way.  While we can't guarantee that after you read this you'll never look back with professional regret, we can help you to avoid some of the most common career mistakes people make:

  1. Staying in the Wrong Job or Career Too Long.  A sense of inertia often keeps people in a job or following a certain career path long after they've stopped enjoying it.  However, the longer you remain in a job or career field you don't like, the worse your attitude tends to become.  Rather than staying in a career you loathe, take steps early on to make a switch once you know it isn't right for you.

  2. Pretending to Know It All.  It can be awkward and uncomfortable to tell our employer that we don't know how to do something.  However, what's more uncomfortable is being called onto the carpet, because you didn't want to admit that you didn't know how to execute the assignment you were given.  Instead, be upfront when you're given a work responsibility that you're uncertain about—most employers will appreciate your honesty and work with you to help you get the training or skills you need to do your job effecively.

  3. Not Negotiating Salary and Benefits.  Women make $.79 for every $1 that men make, and that disparity is typically attributed to salary negotiations.  Rather than just accept whatever a company offers, prepare to negotate.  Do your research in advance about what similar positions in the industry pay and what people with your experience make.  Then, be prepared to present your case calmly and confidently.  This tactic can earn you many, many thousands of dollars more over the course of your career.  And if the company can't adjust your salary, then consider asking for additional benefits like flexible working hours, the ability to telecommute, or an extra week of vacation.   

The Rich ARE Different (And Not Just Because of the Size of Their Bank Accounts)

Interestingly enough, the wealthy are different from others, and it has nothing to do with the amount of money that they have.  According to Steve Siebold, author of How Rich People Think, rich people have different mentalities than their less affluent counterparts.  Below we share some of the ways that Siebold suggests the wealthy differ from you and I:

  1. Wealthy People Believe that Poverty is the Root of All Evil.  The middle class, on the other hand, is more likely to believe that money is the root of all evil.  Siebold explains that the wealthy “consciously build beliefs about money that serve their best interests and help them develop substantial sums.”

  2. Wealthy People Dream of Having Enough Money to Impact the World.  The rest of us tend to dream much smaller.  Primarily, the less affluent among us are focused on just having enough money to retire.

  3. Wealthy People Are Passionate About Their Jobs.  Siebold, who interviewed millionaires around the world, says that they “work because they love what they do and their work is one of the most fulfilling aspects of their lives.  They take the same care selecting a profession as they do selecting a spouse.”  By contrast, the vast majority of the less affluent lack career passion and would quit their jobs if they could afford to do so.

  4. Wealthy People Believe in Self-Reliance.  According to Siebold, the middle class tends to view the rich as people who became wealthy through luck, good fortune, or social advantage.  Wealthy people, however, believe that becoming rich is a choice, and everyone has the opportunity to become affluent.  Essentially, Siebold argues that the wealthy rely on themselves, whereas those who earn less money are more likely to expect someone else to take care of them.

While some of Siebold’s theories are controversial, he suggests that by altering the way you think, you, too, can become rich.  To learn more about his book, click here.

4 Tips for Handling Your New Promotion

So, you just got promoted—congratulations!  A promotion can be a big change, but it doesn't have to be a scary one.  To help you acclimate to your role, we have some tips on how you can best handle your new work responsibilities:

  1. Clarify Expectations.  The very first thing you're going to want to do is meet with your boss and clarify his expectations.  Rather than assuming you know what your boss thinks are the most important functions of your new job, ask—you may be surprised by what he has to say.  Having a clear idea of his expectations will not only make you better prepared for your new role, but it will also help you manage your time more effectively.

  2. Don't Make Changes Right Away.  It's tempting to immediately start making those changes that you imagined making, once you were in a position to do so.  Don't!  Or at least not right away.  The truth is that people are very resistant to change.  Rather than initiating a number of changes as soon as you can, get acclimated to your new position first.  There will be time to implement your ideas in the future, but you want to avoid rushing into things and earning the ire of your subordinates.

  3. Delegate.  Speaking of subordinates, your new role is probably going to involve delegation.  This can be intimidating at first, but it definitely gets easier over time.  Start by asking the people who report to you to do various tasks, but be careful not to go overboard.  You don't, for example, want to hand off all of your work responsibilities so that you can spend most of your day relaxing.

  4. Prioritize.  When we find ourselves with more challenging work responsibilities, we often start cutting back on sleep, exercise, and healthy eating.  However, now is when you need to be more vigilant than ever about taking care of yourself.  The better you treat your body, the easier it will be to stay passionate about your job, rather than becoming burnt out.