5 Fun Facts about Earth Day

Each year, we celebrate Earth Day on April 22nd.   Do you know why?   Learn how Earth Day began and other fun facts about this nature-loving holiday:

  1. An Oil Spill Was the Impetus Behind Earth Day.  After Senator Gaylord Nelson, a Wisconsin Democrat visited a California oil spill, he wanted to mobilize a grassroots movement to call attention to environmental issues.  His idea spread and the first Earth Day was celebrated in 1970 with rallies in cities throughout the country.
  2. The EPA Was Created After the 1st Earth Day.  An astonishing 20 million people participated in the first earth day.  This apparently got legislators’ attention because by the end of the year, Congress authorized the creation of the U.S. Environmental Protection Agency.
  3. Earth Day’s Gone Global.  Once Earth Day was strictly an American holiday.  In 1990, the holiday was recognized internationally with over one billion people celebrating it worldwide.  In fact, it is the largest secular holiday in the world.
  4. Earth Day Has A New Name.  While you won’t hear this name being used much in the US, the UN has renamed the holiday.  As of 2009, Earth Day is officially known as International Mother Earth Day.
  5. Earth Day Is Important for Raising Awareness.  The point of earth day is to help people realize the impact that they have on the planet.  To that end, here are some startling statistics
  • Each year, there are 14,000,000,000 pounds of garbage thrown into the oceans which kills at least 1 million sea creatures annually. 
  • The average person throws away about 4 pounds of garbage a day and uses 12,000 gallons of water a year.
  • Recycling 1 aluminum can saves enough energy to watch 3 hours of television.

5 Surprising Benefits of Exercise

This is that time of year when most people try to sheepishly “forget” about their New Year’s resolutions because they’re not making any progress.  However, if exercising more was one of your goals for the new year, we have some information that is going to make it easier for you to get excited and motivated about your resolution again.  Keep reading to learn more about the unexpected benefits of exercise.

  1. Exercise Reduces the Effects of Stress.  Exercise doesn’t just increase our levels of “good” chemicals like serotonin, dopamine, and norepinephrine, it also can reverse stress’ toll on the aging process, says U.S. News & World Report.  According to a 2010 study, researchers found that stressed women who exercised vigorously had cells that showed fewer signs of aging compared to stressed, inactive women.

  2. Exercise Increases Productivity.  While it might seem that squeezing in exercise would cut down on productivity, that isn’t the case.  Research shows that workers who exercise regularly are more productive and energetic than their more sedentary peers.

  3. Exercise Boosts Creativity.  Research indicates that aerobic activity increases creativity for as long as 2 hours after a workout.  To amp up your stream of creative ideas, try working out in nature—a brisk walk outdoors may just offer the inspiration you’re looking for.

  4. Exercise Improves Sleep.  While it might seem counterintuitive to imagine that exercise actually improves sleep, it’s true.  According to the Mayo Clinic, “Regular physical activity can help you fall asleep faster and deepen your sleep.”  Just make sure not to engage in heart-pounding activity too close to bedtime or exercise may have the opposite effect.

  5. Exercise Can Help Arthritis.  You might imagine that arthritis sufferers should minimize movement to reduce pain.  Not so, research shows.  According to the CDC, doing about 2 hours and 30 minutes a week of moderate-intensity, low-impact aerobic activity can improve pain management and the quality of life for those who have arthritis.

5 Fun Facts about Tax Day

Tax preparation got you down?  While we can’t do your taxes for you, we hope to alleviate your pain a little bit by sharing 5 fun tax facts with you:

  1. Nobody Can Agree.  If you’re worried about whether you did your taxes correctly, perhaps you can breathe a little easier knowing that even tax professionals disagree.  When 50 tax preparers were asked to do the tax return of a single family, they came up with nearly 50 different answers!

  2. Even Geniuses Are Baffled.  Many view Einstein as one of the smartest people to ever live and even he once said, “The hardest thing in the world to understand is the income tax.”  Mind you, they’ve only grown progressively more complicated since Einstein’s time.

  3. The Tax Code Is Ridiculously Complex.  For instance, did you know that there are a whopping 4 million words in the US tax code?  That’s 5 times the number of words in the Bible!  Back in 1913, the federal tax code was a mere 400 pages.  Today, it is an anxiety-inducing 70,000 pages.

  4. Americans Spend 7.6 Billion Hours Annually on Tax Preparation. Ouch.  With there being roughly 312 million people in the US according to the Census Bureau, that works out to 24.4 hours getting ready for tax season for each man, woman, and child.

  5. Drive Safely.  Interestingly enough, traffic incidents increase around April 15th.  Rather than rushing to the post office, drive the speed limit and practice caution.  Or better yet, consider filing your taxes from home electronically.  While more than 20% of hard copy tax returns have errors, less than 1% of electronic returns do.

Thought For The Day

“The supreme accomplishment is to blur the line between work and play.”

Arnold J. Toynbee

 

Lambda Operator in C++

Today we are going to talk about a concept introduced in C++11 called lambda expressions (sometimes also referred to as closures).

Many programming languages support the concept of anonymous functions - functions that have a body, but do not have a name.  A lambda expression is a programming technique that is related to anonymous functions - you can write a lambda function inline in your source code.  We can think of a lambda expression as an anonymous function that maintains state and that can access the variables that are available to the enclosing scope.  The very concept of a lambda function originates in the lambda calculus and functional programming.

Let's see what we need to define a lambda function:

  • The capture list
    The capture list is a list of captures: it defines what should be available in the lambda function from the outside.
    A capture can either be a capture by value or a capture by reference:
    1. [x] - a value
    2. [&x] - a reference
    3. [&] - any variable currently in scope by reference
    4. [=] - any variable currently in scope by value

  • The argument list
    The argument list is the same as with any other function in C++.

  • The body
    This is the part of the code that will actually be executed when we call the lambda function.

 

Let's see some examples:
First, in order to use lambda expressions, we have to write

#include <functional>
Lambda expression:
auto f = [](int a, int b){return a + b;};

The auto keyword specifies that the type of the variable that is being declared will be automatically deduced from its initializer.  For functions, it specifies that the return type is a trailing return type or will be deduced from its return statements.

In our example, the compiler will deduce that we have declared a function: precisely, a function with the following signature:

std::function<int(int, int)>
This enables us to write things like:
auto x = [](int a, int b){return a + b;}(2, 3); // int x = 5
We can also specify the return type like this:
auto x = [](int a, int b) -> double {return a + b;}(2,3);

/*If we check the type of x, we see that it's, in fact, a double*/
std::cout << typeid(x).name(); //d
An example with capturing:
int main()
{
  int a = 2;
  auto f = [&](int x){return x + a;}; //capturing everything in scope by reference; we could have also written [&a] to capture only a
  int y = f(1);
  std::cout << y; //3
}

 

Of course, these examples are trivial and it might be difficult to see the advantage of using lambda expressions.  For the end of this article, consider this next example which should give you an idea of how lambdas can be used.

int array[] = { ... };

std::sort(array, array + sizeof(array), [](int a, int b) {return a > b;}); //the lambda function determines the criteria on which the array will be sorted

/*or if we have an array of points...*/
std::sort(array, array + sizeof(array), [](Point a, Point b) {return a.getX() < b.getX();});

Informally speaking, the main advantage of an anonymous function is that it is a full scale object that can be taken and sent somewhere.  Anonymous functions are popular now because of their suitability for big data applications.  One function can be run over a list to get another list, then another function can be run, then another, then finally grouping the elements with last function and so on – essentially, feeding a list with functions, rather than feeding a function with lists (as in more traditional programming).