Cities for the People

Today’s cities are designed for vehicles, not for people. Modern cities have an overwhelming presence of cars, and parking lots, and contain very few parks. Some cities don’t even have adequate sidewalks, or bike lanes, and lack the basics of public transportation. Modern cities are also a lot larger, and have more people than they’ve ever had in the past. More than half of all people live in cities, some of which are living in megacities, with over 10 million residents. Many of these cities contain air that isn’t safe to breathe. Living in these overpopulated areas can pose serious health risks, and the constant congestion of streets cause frustration levels to skyrocket (Brown, 2009).

Cities and Global Warming

Does the current design of our cities contribute to excess CO2, and global warming? The simple answer is, yes, albeit indirectly. Cities are designed for vehicles, not for people. They are inlaid with concrete highways, ramps, bridges, and lanes, making it impractical to get around using any other means of transportation. They are congested with vehicles, and, in megacities, bumper-to-bumper traffic; raising stress levels of people living, or commuting, within their borders. The constant flow of traffic and congestion causes havoc on the environment by releasing massive amounts of CO2 into the atmosphere, helping to increase the rate in which global warming progresses. The null hypothesis is that: If cities were designed for people, instead of cars, then there would be a decline (or at least stabilization) in the current global warming rate.

Current internal combustion engines (ICE), are one of the leading causes of pollution. Some companies, such as Toyota, and Honda, are industry leaders in creating safer, and more fuel-efficient vehicles (Laszlo, 2008). Over the next 20 years, an additional 600 million vehicles are projected to enter the market, bringing the total number of vehicles to an estimated 1.5 billion. These vehicles not only release excess CO2 into the atmosphere, but they also contribute to the formation of ground-level ozone, and smog, which can result in health conditions such as asthma (Laszlo, 2008).

Continue reading “Cities for the People”

Economic Analysis of Sustainability

Oil is the world’s leading source of energy. In 1900, the world produced 150 million barrels of oil, a number that jumped dramatically to 28 billion barrels by the year 2000. In the twentieth century, oil was readily available, and, therefore, very cheap. This expanding supply of cheap oil caused an explosion in the growth of food production, population, urbanization, and human mobility (Brown, 2009). Today, we live in an oil-based civilization, and are completely reliant on an energy source that will not be around forever. There is an estimated 2 billion barrels of oil on the planet, of which, 1 billion barrels have already been used (Brown, 2009). Aside from the dramatically decreasing oil quantities, the burning of oil also contributes to global warming. According to Brown, 2009, the burning of oil contributes to 38% of all carbon emissions, succeeded only by coal, which is currently responsible for 43% of all carbon emissions.

Economic Analysis of Sustainability

The Earth’s temperature has been increasing over recent years. 25 of the world’s warmest years since records have been kept, have happened since 1980 (Brown, 2009). This warming happens because of greenhouse gasses, like carbon, which trap heat inside the Earth’s atmosphere. Carbon is currently responsible for 63% of the global warming trend (Brown, 2009). One of the main causes of carbon emissions comes from transportation. In 2010, there was an estimated 250.2 million registered passenger cars on the road, in the United States alone (RITA, 2012). In 2011, the number of vehicles worldwide surpassed 1 billion (Tencer, 2011), with the United States being the worst culprit. Even though the number of vehicles in China has been dramatically increasing, they would need to increase their vehicle numbers another 16-fold, just to meet the number of vehicles currently on U.S. roads (Tencer, 2011).

The release of carbon from vehicles contributes to the effects of global warming. Carbon prevents the Earth from cooling down, by trapping heat inside the atmosphere. When sunlight hits glaciers, about 70% of that heat is directed back into space, but because of the carbon build up, this heat can be trapped in the atmosphere, which causes the glaciers to melt even faster. As the glaciers start to melt, more open ocean is exposed. Only about 6% of light that hits the dark-colored, open ocean, is reflected back into space, leaving the rest of the heat from the light, to be absorbed by the ocean, heating the water. As the ocean waters warm, they also contribute to the melting of the glaciers. This creates what scientists call a Positive Feedback Loop. To make any progress in the fight against global warming, we need to find ways to remove excess carbon from the atmosphere.

Continue reading “Economic Analysis of Sustainability”

Marketing Defined

I used to think that marketing was just a push to sell products to everyone by spamming them with advertisements, and other sales pitches. However, marketing is much more than that. A producer shouldn’t be trying to sell a product or service after it has been developed. They should only be developing goods that they’ve verified, through research, that the consumers want to purchase. If you start by determining what consumers want, or need, and develop new products or services based on that, you’ll have a much easier time trying to sell your goods.

When you determine what the consumer wants, you also need to determine how much the consumer is willing to pay for the goods. You need to figure out who your competition is, if any, and how much they are charging for the same goods. You need to figure out if you can afford to provide, or produce, the goods at the price the consumers are willing to pay. If the producer can’t make a profit from the goods, there is no sense in moving the idea forward.

The marketing process doesn’t stop there. You also need to figure out how to support, maintain, and provide warranty services, if needed, for the goods produced. The key here, is making sure that you keep the consumers coming back to the same producer in the future. If you just push the goods out the door, and the consumer isn’t satisfied with what they’ve received, they’ll probably choose another producer in the future. If this happens, the marketing process has failed.

Continue reading “Marketing Defined”

Suicide Island

There is an island, upon which a tribe resides. The residents either have blue eyes, or brown eyes. Yet, it is taboo to talk about eye color in any way. Thus, one resident can see the eye colors of all other residents, but has no way of discovering his own (there are no reflective surfaces).  If a resident does discover his or her own eye color, then he or she must commit ritual suicide, at 12-noon, the following day, in the village square, for all to witness.

Note: Everyone on the island is perfectly logical. On this island, there are 100-blue-eyed people, and an unknown number of brown-eyed people.

On day zero, a traveler comes to the island, and says aloud for all residents to hear:

“On this island, there is at least one person with blue eyes.”

Having said that, he departs; on day 100, all 100-blue-eyed people commit suicide simultaneously. Explain the logic behind these suicides.

Corollary: Why is the traveler important?

Identification of the problem

One crux to this problem, could be the fact that the people on the island are perfectly logical. If the people weren’t logical, they wouldn’t be able to make conclusions about other people’s eye colors, or, about their own eye color. This would make the traveler completely irrelevant.

The traveler is important, because he or she starts the count, and gets things rolling. If the traveler hadn’t come to the island, and made the statement about at least one person having blue eyes, none of the people on the island would have been able to figure out their own eye color, and they would all still be living happily ever after.

If either of the two situations above weren’t true, or didn’t happen; everyone on the island would still be alive. The people on the island only died because they were both perfectly logical, and, the traveler came.

Analysis

This problem can be solved using multiple cases, with smaller, more manageable numbers. It’s hard to consider the entire problem at once, but if we break the problem down, it becomes much easier to understand.

Case 1: To start off, let’s assume that there’s only one blue-eyed person on the island. Let’s name this person, Mark. This will make the problem a little easier to understand. The traveler comes to the island, and states that he sees at least one person on the island with blue eyes. Mark, the person with blue eyes, looks around the island, and notices that everyone else on the island has brown eyes. From this, Mark concludes that he must have blue eyes, and, therefore, kills himself at noon the next day.

Mark can make this conclusion because the traveler stated there was at least one person with blue eyes on the island; however, he can tell that everyone else on the island has brown eyes, by looking at them.

The other people on the island notice that Mark killed himself, and therefore, must have figured out his eye color. When the other people on the island see, that Mark has blue eyes, they put that together with what the traveler stated. Since they are perfectly logical, they also realize that this means Mark must not have seen anyone else on the island with blue eyes.

This information leads everyone else on the island to conclude that they have brown eyes. At noon, the next day, everyone remaining on the island kills themselves.

Case 2: In case two, we will have two blue-eyed people. We’ll name them Mark, and Bob. After the traveler comes to the island and makes his statement, both Mark and Bob look around the island at everyone else.

Mark looks at Bob, and notices that Bob has blue eyes, but everyone else on the island has brown eyes. Mark assumes that Bob will kill himself at noon the next day, but when Bob fails to kill himself, Mark deduces that Bob must see someone else on the island with blue eyes. Because Mark is perfectly logical, he knows that this means he must have blue eyes.

At the same time, Bob notices that Mark has blue eyes, but everyone else on the island has brown eyes. Bob also assumes that Mark will kill himself at noon the next day. When Mark fails to kill himself, Bob concludes that Mark must see someone else on the island with blue eyes. Bob realizes that he must be the other person with blue eyes, and both men kill themselves at noon the next day.

When the rest of the people living on the island notice Mark and Bob kill themselves, on day 2, they realize that they must all have brown eyes, and, therefore, kill themselves at noon on day 3.

Case 3: We’ll use three people in this case. At this point we can continue to use the previous case to help us solve the problem. We already know that Mark was waiting for Bob to kill himself, and vice versa. Let’s add the third person into the problem. We’ll name him, Jim.

In this case, Jim is also waiting for Mark and Bob to kill themselves; however, just as in previous cases, when Mark and Bob fail to kill themselves on day 2, Jim realizes that there must be another person on the island with blue eyes. He can conclude this because neither Mark, nor Bob, have killed themselves, and, therefore, they must see another person on the island with blue eyes.

Just as in previous cases, Jim looks around, and notices that everyone else on the island has brown eyes, and, therefore, he must be the other person with blue eyes. There are a few things that are happening here:

  1. Mark is waiting for Bob, and Jim, to commit suicide
  2. Bob is waiting for Mark, and Jim, to commit suicide
  3. Jim is waiting for Mark, and Bob, to commit suicide

Because none of the men are killing themselves, they conclude that they all have blue eyes, and, therefore, they all kill themselves at noon on day 3. When the three men kill themselves, the rest of the people living on the island instantly know that they all have brown eyes. After learning their eye color, the rest of the people on the island commit suicide at noon the next day.

Case N: From the previous cases, you should be able to notice the patterning that is arising. This information can be used to construct an algorithm to help solve the larger problem.

In case 1, we had one blue-eyed person. That person killed themselves on day one, and everyone else killed themselves on day two. In case 2, the two-blue-eyed people killed themselves on day two, and everyone else killed themselves on day three. Similarly, in case 3, the three-blue-eyed people killed themselves on day three, and everyone else, on day four.

We’ve used a minimum of three cases to prove that a pattern exists. Now that we know there is a pattern, we can solve the finial problem. We could list out every case, up until day one hundred, or, we could take a more logical approach to reach the solution.

The case-number itself, directly reflects the number of blue-eyed people in the problem. Case 1 had one blue-eyed person; Case 2 had two blue-eyed people, and so on. This means we can substitute the letter N (meaning number of blue-eyed people, in this case) for the number of blue-eyed people in our problem.

Case (N): We can break Case N down into two sub-cases: N0, will be the day in which all the blue-eyed people will die, and N1, will be the day in which everyone else on the island dies. If we substitute N, for the number of blue-eyed people, we can figure out when everyone is going to die.

The sum of N, plus its sub-case, will provide the answer we need:

  • Case N = {x | x ϵ N and x is the number of blue-eyed people}.
  • Case N+0 = Blue-eyed people die.
  • Case N+1 = Brown-eyed people die.

Heuristics

  • We used multiple cases to help break a large problem down, into more manageable pieces.
  • We constructed a simple algorithm to help solve the problem.

Looking Back

I think this is a silly problem. First, it states that everyone is perfectly logical. Why would anyone that is perfectly logical, kill themselves over eye color? If the people really were perfectly logical, they would use their logic to put together a raft, and sail away from the island, while waving their fists, and telling the rest of the inhabitants to “stuff” their crazy laws.

But on the bright side of things, if you happened to be lucky enough to have brown eyes, you get to live one day longer then everyone that had blue eyes. On the down side, you had to watch 100 blue-eyed people commit suicide, which is probably the real reason, why all the brown-eyed people killed themselves, the following day. Either that, or they all died from heat stroke, while attempting to dig 100 graves.

Number Sets

Task: List the sum of all numbers between 7,777, and 70,000, where the numbers are divisible by 7.

Identification of the problem

The crux of this problem is to break the larger numbers down, into smaller sets, or groups, so that we can try and identify some type of pattern to work with. To solve this problem, we’ll need to calculate the sum of all the numbers between 7,777, and 70,000, but only for those numbers that are divisible by seven.

Analysis

We’ll need some type of chart to help us understand the numbers we’re working with. It would be unrealistic for us to list all the numbers between 7,777, and 70,000, so we’ll work with a smaller list:

7,777 + 7,784 + 7,791 + … + 69,986 + 69,993 + 70,000

The numbers we’ll be working with are listed above. I’ve used an ellipse, to signify that there are missing numbers. This is much more practical than trying to list all the numbers. The list shows that the numbers start at 7,777, and continue, counting by seven, until the number 70,000, has been reached.

The problem asks us for the sum of all the numbers that are divisible by seven. Using this information, we can dramatically decrease the size of our list, as I have done above, by incrementing the numbers by seven.

Basic math skills will tell us that the number 7,778, is between 7,777, and 70,000; however, we’re not interested in that number, because it’s not divisible by seven. By incrementing the list by seven, I’ve excluded all the numbers that will have no effect on the outcome of this problem.

Continue reading “Number Sets”

Mr. & Mrs. Anbouba

Mr. & Mrs. Anbouba recently attended a party, at which, there were three other couples. Various handshakes took place. No one shook hands with their spouse. No one shook his, or her, own hand. No one shook hands with the same person twice. At the end of the evening, Mrs. Anbouba asked the seven-other people, how many hands he, or she, had shaken. Each person gave her a different answer. How many hands did Mr. Anbouba shake?

Identification of the problem

The crux of this problem, is to alternate extremes, so that we can eliminate possibilities. One way we can solve this problem, is to use a few diagrams to assist us in obtaining a solution.

Analysis

For the first part of the problem, we need to figure out the maximum number of handshakes that are going to be possible. We know that there are two people in a couple. The problem states that Mr. & Mrs. Anbouba recently attended a party, at which, there were three other couples. From this, we can conclude that there must be four couples total. Mr. & Mrs. Anbouba being one couple, and three other couples, whose names we don’t know. This proves that we have a total of eight people.

The problem also states that no one shook hands with their spouse, and no one shook hands with themselves. Now that we have this information, we can form a simple math equation, that will tell us the maximum number of handshakes we will have.

We’ll take the total number of people at the party, and remove the two people (yourself and your spouse) that you cannot shake hands with. Now we have a formula we can use to solve the first part of the problem:

Formula: total people – (self + spouse) = max handshakes, Or 8 – (1 + 1) = 6

That formula tells us that the maximum number of handshakes, any one person can have, will be six. Now, we’ll need to figure out the minimum number of handshakes a person could have.

Continue reading “Mr. & Mrs. Anbouba”

Encapsulation with Property Accessor Rescoping

A better way with Property Accessor Rescoping

Overview

I have seen many questions about the correct design of a solution that needs to keep fields completely encapsulated, and control who, and what, can write to these fields. There are three key components to encapsulation.

The Field

The field is the human-readable name that corresponds to the location where the actual data is stored in memory. The field is sometimes referred to as a variable.

The Property

The property ensures the field is encapsulated and exposes the field so it can be seen by instances (or derivations) of this class. You’ll notice that the property has the same name as the field, except it starts with a capital letter. It’s not required that your property and field have the same name; however, it’s good practice to do so, and it makes your source code more legible.

The Accessor(s)

The accessors allow the field to be written to, and read from, in a controlled manner. In the code example below, the accessors simply read and write the data; however, you could run other statements here, before writing to the field; such as data validation statements. You can create a read-only field by omitting the set accessor, and a write-only field by omitting the get accessor.

public class Member
{
    // This variable is called a field.
    private string firstName;

    // This is the property.
    public string FirstName
    {
        // These are the accessors.
        get { return this.firstName; }
        set { this.firstName = value; }
    }
}

The Old Way

This solution allows you to read and write to the field via its property, and accessors, rather than accessing the field directly. It allows you to perform validation, or check the data in any other manner to ensure it’s safe before attempting to write it into memory. It allows you to control who, and what, can access the field. This ensures that no instances or derivations of this class can access that field directly (notice the field itself is private).

public class TheOldWay
{
    // Field.
    private string firstName;

    // Property.
    public string FirstName
    {
        get { return this.firstName; }
        set
        {
            // run validation (or other) statements here.
            this.firstName = value;
        }
    }

    private void Method1()
    {
        // Writing directly to the field.
        this.firstName = “Ken”
    }

    private void Method2()
    {
        // Writing to the field via its property.
        this.FirstName = “Ken”
    }
}

In this example, both Method1, and Method2, write the name “Ken” into the firstName field. However, only Method2 will guarantee that the name will be validated in some way, or that some other statements will be executed prior to saving the new name into the field.

You may not want to perform the validation directly inside the set accessor, in most cases it’s a bad design; however, look at what we can do here:

As soon as the set accessor is accessed, we mark this class as invalid. This it will prevent any critical methods from executing until the class has been validated. You can also make the property IsValidated public, so it can be called from outside this class, and executed, on the current instance, whenever it may be required.

public class SetIsValidatedBool
{
    private string firstName;

    // Tracks this objects validation status.
    private bool isValidated = false;

    public string FirstName
    {
        get { return this.firstName; }
        set
        {
            this.firstName = value;

            // The first name was changed. It may be invalid.
            IsValidated = false;
        }
    }

    // Notice even the validation flag is encapsulated.
    private bool IsValidated
    {
        get { return this.isValidated; }
        set { this.isValidated = value; }
    }

    // Constructor- When this class is created. A first name must be passed.
    public SetIsValidatedBool(string theFirstName)
    {
        // We received a new first name, most likely from a text box control.
        // Go ahead and use it.
        this.FirstName = theFirstName;
    }

    // Simple validation method. Checks to see if the first name provided
    // is less than 5 bytes.
    private bool SomeValidationMethod()
    {
        if (this.FirstName.Length < 5)
        {
            // return some error message here...
            return false;
        }
        // The first name is larger than 5 bytes. It is OK to use.
        return true;
    }

    // This can be called from an instance of this class.
    public void DoSomethingWithThisObject()
    {
        // Before we do anything make sure this object has been validated.
        if (!IsValidated)
        {
            // Throw an exception or take some other action here. This class
            // instance has not been validated yet.
        }

        // This class instance has been validated. Place code here to
        // do something with this class.
    }
}

One problem with this, is that we may be working with data other than a first name. We may want the field available for instances of this class to read, but not write. Normally, this could be done in a few different ways. I’ll show you some of the older, and in my opinion, the wrong ways, to do this first. Then I’ll show you how you can use property accessor rescoping to your advantage.

public class WriteDirectlyToField
{
    // Field.
    private string someCriticlePeiceOfReadOnlyData;

    // Read only property. Only a get accessor has been coded.
    public string SomeCriticlePeiceOfReadOnlyData
    {
        get { return this.someCriticlePeiceOfReadOnlyData; }
    }

    public void SomeMethod()
    {
        // some statements here...

        // Write directly into the field. Since we cannot write into the
        // field via its accessor.
        this.someCriticlePeiceOfReadOnlyData = “1234”
    }
}

The previous example creates a read-only property for the field. Since there is no set accessor in this property, nothing can write to the field via its property. So, we need to set the data directly into the field itself. This is a bad idea, because our data is no longer encapsulated. Even though its being set from within the class its declared in, it’s still not a good idea to write directly into that field. In the former example, doing this would not set the isValidated flag. We are setting a constant value here, so we know it should be safe. In a real-world solution, there is no telling where this data: “1234”, is going to come from. It may come from another class, a file, or even from the Internet.

Another reason this makes a very bad design is because many methods from within this class may need to write to that field, therefore, things will very quickly get out of hand, trying to track down what methods are writing to that field, and at what time.

public class SimulatedSetAccessorMethod
{
    // Field.
    private string someCriticlePeiceOfReadOnlyData;

    // Read only property.
    public string SomeCriticlePeiceOfReadOnlyData
    {
        get { return this.someCriticlePeiceOfReadOnlyData; }
    }

    private void SomeMethod()
    {
        // Some statements here...

        // Call up our simulated set accessor method, and pass the data
        // that needs to be writen into the field.
        Set_someCriticlePeiceOfReadOnlyData(“1234”);
    }

    // Simulated set accessor.
    private void Set_someCriticlePeiceOfReadOnlyData(string theData)
    {
        this.someCriticlePeiceOfReadOnlyData = theData;
        
        // If we had an IsValidated bool in this example, it could be set
        // to "true" here. It would invalidate the class.
    }
}

The previous example is a little bit better. Now the field would technically be encapsulated, and if we always write to that field via our simulated-set-accessor method, the isValidated flag will always be set for us. There are some bad points to this solution, however.

For number one, this just adds one more method to the class, helping to clutter it up. Secondly, some people would argue that this is very clear. “It’s clear that this method writes to that field, and that this is an attempt to encapsulate the data.” However, when working with real-world solutions, we will rarely only have one field per class. There is also no guarantee that this method will be kept directly underneath the read-only property, for the field, where it can be visible at a glance. Code may be added between them, or around them (as I have done in this solution), and, sooner or later, this method is 60+ lines down the class from our property for the field. Now you’re stuck trying to locate the method amongst all the other code. You will need to be scrolling up, and down, in an attempt to understand the class. Even when care is taken, things can get misplaced, and unorganized, very quickly.

A Better Way

This example is like the former example, except that it removes the need for our simulated-set-accessor method, and re-scopes the property itself. Notice, we have changed the scope of the set accessor to private:

public class TheBetterWay
{
    // Field
    private string someCriticlePeiceOfReadOnlyData;

    // Read only property.
    public string SomeCriticlePeiceOfReadOnlyData
    {
        get { return this.someCriticlePeiceOfReadOnlyData; }
                       
        private set /* RESCOPED */
        {
            this.someCriticlePeiceOfReadOnlyData = value;
                
            // If this example had an IsValidated bool it could be set
            // to "true" here. Invalidating the class.
        }
    }

    private void SomeMethod()
    {
        // Write to our field via its rescoped accessor. If you attemped to
        // write to this field via its property from an instance of this class
        // you would receive a compilation error.
        this.SomeCriticlePeiceOfReadOnlyData = “1234”;
    }
}

This is an excellent solution because it keeps all our accessors inside the field’s property, and, it’s easy to understand (if you understand scoping). You can clearly see that this property has a public scope, therefore, any instance, or derivation, of this class, will be able to read the critical data; however, since we have re-scoped the set accessor to private, only the class within witch it is declared, can write to the property. If you were to try to write to this field from an instance of this class, you would receive a compilation error. In this example, the data is always encapsulated, and the isValidated flag will always be set, when the critical data is changed.

Conclusion

There are two rules you must follow when using this type of solution:

  1. You can re-scope only one accessor per property. Therefore, if you re-scope the set accessor, you cannot re-scope the get accessor, and vice versa. One reason being, is that if you are going to re-scope both accessors, you should just re-scope the property itself, and not the accessors. It would make no sense to have a public property with two private accessors inside of it. Just re-scope the property itself, to private. If you were to re-scope both accessors with a different scope, simply place the more accessable scope at the property level, and re-scope only the remaining accessor.
  2. The second rule you must follow, is that the re-scoped accessor must be less accessible then the property’s scope itself. You cannot have a public accessor inside of a private property.

This Game We Play

Locked away, covered in code, compiling this, compiling that, hacking this, whoops, shouldn’t say that! Scary isn’t it? You just never know, who’s watching you now, shaxor, time to go, on the move, one more time, got to stay ahead. This game we play, this game they play, behind the board, amazing now, scanning this, what’s up with that? Your open now, they’re hiding it now, you try and say this, you try and do that, either way you go, they got you now! Your on the move, this game we play, isn’t it nice? What’s your name? It’s different now, your crazy now, they don’t believe you now, you’re running now, call them now, they can’t help you now. It all breaks down, it’s on the line, next line is mine:
– Kenneth R. Jones © 2005