Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.

Share tech news, updates, or what's on your mind.

Sign up to Post

Many programming languages have a Switch–Case capability. Since its first beta in 2003, AutoHotkey has not had one. Finally, in the recent 28-Sep-2019 release of Version, it now has Switch–Case. This article discusses it and shows a sample usage as applied to a previous post here at EE.

Expert Comment

by:Luis Diaz
Very useful article! Glad to know that an alternative to if-then through switch-case statement is available in AutoHotkey!
LVL 69

Author Comment

by:Joe Winograd
Hi Luis,
Thanks for the compliment and the article endorsement...both very much appreciated! Regards, Joe
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data definitely won't be found. Read on to find out more...
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
Exception Handling is in the core of any application that is able to dignify its name.
In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This question got me thinking...

Why shouldn't we use Globals?
This is a simple question without a simple answer.  How do you explain these concepts to a programmer who is coming from a background in procedural programming? 

There is a lot of deep background thinking that you need to understand in order to know why globals are considered to be a poor design choice today.  Singletons are just as bad as globals in many ways.  Often procedural programmers have looked at the global keyword as an expedient solution - a global declaration made inside your functions provided a simple reference to an external database connection.  Tightly-coupled code sets were the norm in programming just a few years ago, and the global keyword implemented tight coupling in a way that irrevocably bound certain objects into the fabric of the application.   If you're working alone on a standalone project, you can sometimes get away with using global objects, but if you want to come into the modern world of application design, and especially if you want to collaborate on anything important, you need to understand why global elements are considered harmful, and what the alternatives offer.

Global Variables Break Encapsulation
LVL 111

Author Comment

by:Ray Paseur
I may have to sign off on this because I'm not following the part about passing an object three levels deep.  It looks like the $db variable is injected into the constructor of the Contact class and used in its methods.  That seems fine to me.  The granularity level for testing is the Contact class, since the $db is the same throughout all the methods.

A "config" class sounds like a singleton to me - similar to a global, but I would have to read the code that sets it up and uses it.  Maybe a consulting agreement would make sense here?
LVL 32

Expert Comment

No, I'm satisfied with getConfig(). I was just trying to understand if there was a better way. But your feedback is appreciated.
This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the case for informational sites) and for this reason, the site should be able to recognize repeated identical requests and return an immediate cached response, rather than going back to the database queries for the reformulation of the original response. 

The rationale for this strategy comes from recognition of the difference in speed between in-memory processes and disk-based processes.  While memory access is typically measured in nanoseconds, even a very fast disk spinning at 7200RPM requires 8.3 milliseconds for a single rotation, and the nature of file lookup or database operations is such that a great many disk rotations may be required for some queries.  Since the ratio of nanoseconds to milliseconds is several orders of magnitude, it follows that cache may produce substantial quantitative improvements in server performance.

Characteristics of a Cache
Popular cache systems include Memcached and Redis, and it is also possible to use the file system for cache storage, but in-memory systems will give the best performance.  All cache systems work in similar ways.  They are key:value data storage systems.  Access to a value in the cache is made …
A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely principles, like "an apple a day keeps the doctor away." But they serve to guide us in the right direction as we design and build our systems.

There are no real "shortcuts" here.  As Euclid said to Ptolemy, who wanted to know the easy way to learn geometry, "There is no royal road to geometry."  So, too, there is no royal road to good object-oriented design. But that said, read on for some of the summary and background information that will make your software designs more coherent and easier to build, test, extend and reuse.

Do I Really Have to Learn This?
What happens when these principles are ignored?  Some call it software "rot."  I prefer to think of it in terms of fragility and viscosity.  Software that is of fragile design is difficult to extend or modify.  Even simple changes can induce seemingly unrelated entropy elsewhere in the system (Einstein called this, "spooky action at a distance").  Eventually this phenomenon comes to the attention of the business managers, and they become resistant to change.  Developers become frustrated as micromanagement ensues.  Ultimately the system must be scrapped and re-invented.

Software that is viscous
LVL 111

Author Comment

by:Ray Paseur
Thank you, Todd.  As time permits I will have five more articles in the series to illustrate each of the principles at work in PHP.
Many of the most common information processing tasks require sorting data sets.  For example, you may want to find the largest or smallest value in a collection.  Or you may want to order the data set in numeric or alphabetical order.  The correct data structure for this kind of work is the array.  Fortunately PHP provides an excellent collection of built-in array sorting functions.  These functions can re-arrange arrays in ascending or descending sequence.  They can preserve or renumber the keys.  They can even sort in "natural order" just like a human being would sort a collection, ignoring case-sensitivity in the data set.  And if everything you need to sort can be expressed in a one-dimensional array, one of the PHP built-in array sorting functions will surely do the trick.

Finding the Minimum and Maximum Values in a One-Dimensional Array
If you need to find a single min/max value, PHP has built-in functions to do the work for you.  For this simple task, you do not need to write any code.  Just call the PHP function that suits your needs.  Choose either min() or max().

But if there are any "interesting" edge cases, you may want to read the man pages carefully.  Because PHP is a loosely typed language, these comparisons are done under rules of type-coercion.  PHP will interpret the values in ways that allows PHP to make a duck-typed comparison.  Which value do you think would be the minimum among these array elements:
$arr = [2, '2', Two];

Open in new window

LVL 29

Expert Comment

by:Bernard Savonet
Seems that the ->key use you describe will be ghe solution to my previous use of usort wjth the argument array passed by reference, now deprecated.

Expert Comment

by:renush raaz
Here I presenting a new features  of Microsoft's windows 10 is windows alarm and clock,  this windows features is very helpful in working time cause by this features set the timing set alarm clock windows 10  of on/off system in proper means i says that your laptops and your computer wake up from sleep mode in the set time thus that's why it uses such like time manager.
Dependencies in Software Design
In software development, the idea of dependencies is an issue of some importance. This article seeks to explain what dependencies are and where they can create a problem for growth or an opportunity for excellence.

In a nutshell, if program "A" calls upon program "B" for some data or service, program "A" is said to have a dependency on program "B." If the interface that program "A" uses to call program "B" changes, then program "A" must be changed, too. This sort of situation may be easy to fix if it is an isolated case (perhaps all calls to program "B" are routed through a particular class method in program "A"). However if the coupling is not an isolated interface, the dependency on program "B" can be a real risk to the continued health of program "A."

To try to illustrate this in practical terms, let's consider an issue that many PHP programmers are facing right now. They developed web sites or web applications that are dependent on the familiar but obsolete MySQL extension. Throughout their scripts, we find numerous instances of mysql_connect(), mysql_query(), mysql_fetch_assoc(), etc. There are red warning labels on all of those main pages! It has been a couple of years since PHP deprecated the MySQL extension

Expert Comment

Another great article! I have started using DI more and more in my code. I have not as yet done much with phpunit and automated testing, largely because there does not seem to much in the way of real-world, yet easily approachable "getting started" material. For example, many tutorials start with the obligatory test add function. assert that a call to add(1,2) equals 3. This is all well and good, but then they fall off quickly and do a bit of handing waving over mocks, stubs, automation, etc. But I digress.

One question I have about DI, is how to decouple use of global functions (particularly in a framework). After all, PHP is essentially a language and a framework. I total get DI with objects. For example, instantiate an object, then pass that instance into a function or method of another object.

But what about decoupling functions?

A bit of a contrived example:

class Gatekeeper
    public $passphrase;
    private $secret;

    function __construct($phrase) {
        $this->passphrase = $phrase;

   private function validate(){
       return $this->secret == md5($this->passphrase);

  public response(){
     if ($this->validate()){
         return 'Welcome. May I take your coat?';
         return 'Get lost!';

Open in new window

// The above code is dependent on MD5. MD5 is a function, not an instantiable class; what is best practice to inject this dependency analogous to:

$JoeTheBouncer =  Gatekeeper('Shazaam', md5);

Open in new window

The Fluent Interface Design Pattern

You can use the Fluent Interface design pattern to make your PHP code easier to read and maintain.  "Fluent Interface" is an object-oriented design pattern that resembles message handling, where a message is passed from program to program, with each program adding a bit of value to the message.  It was first given its name about a decade ago by Martin Fowler, and is now in wide use in the PHP world, considered a "best practice" by industry leaders.  Fluent design allows us to do rapid application development with Laravel, and facilitates formalized automated application testing with PHPUnit.  One of the defining principles of the design pattern is code that is "primarily designed to be readable and to flow."  One of the most delightful effects of using a Fluent Interface design is the elegant simplicity of method chaining.

Before we see a Fluent Interface in practice, let's look at some programming activities we have all encountered before, and the steps (and missteps) we have used to solve our problems.  A good example is the Address Book or Contact Directory.  When we start writing this application, we think, "Well, I need names and phone numbers."  And that is fine for starters, but right after you get it all set up, the boss comes in.  "Don't forget that you also need email addresses."  

OK, no problem, we can add that field to our data model.

Here's what an original data model might look like (in prototype):

Open in new window

LVL 25

Expert Comment

by:Marcus Bointon
Personally I'm not bothered about the syntactic sugar a fluent interface brings (as per the SO question you linked to - this example is really method chaining rather than fluency as other than save() it has no semantic value). While I agree that this makes some code very readable (it's a great fit for SQL query building), it has big implications for error handling. Because you never get an opportunity to return an error (you always have to return $this), the only way to handle errors is to throw exceptions (trigger_error amounts to the same thing), so your function call chain needs a potentially large number of exception handlers, this sort of thing:

try {
} catch (invalidNameException $e) {
} catch (invalidPhoneException $e) {
} catch (invalidEmailException $e) {
} catch (saveFailedException $e) {
} catch (Exception $e) {

Open in new window

While this retains the interface, the error-handling path gets disconnected from the flow. Also note that once you've thrown an error, there's no way of getting back into the call chain to fix the problem and continue - you have to start again.

There is a ton of debate on exceptions vs return values, but broad exceptions are great way of handling large-scale problems, for example your database connection breaking when you're busy thinking about something else.


This article discusses the Chain of Responsibility pattern, explaining

  • What it is;
  • Why it is; and
  • How it is
At the end of this article, I hope you will be able to describe the use and benefits of Chain of Responsibility.


In your programming career, you might have faced the scenario where you have multiple commands or requests and each command must be processed in some specific way. For that we create handler objects that process those commands. We create those command handlers in a one to one mapping fashion, i.e. one handler for one command or request.
Generally, handlers are selected by the type of request, and this is done by a method that might handle the selection via an if/then/else statement, though in some cases typeOf or type checking is used. The problem is with the "if" condition. This kind of common problem can be resolved easily by designing an object hierarchy based on good object-oriented design principles. One of the best applicable patterns is described by the Gang of Four as "Chain of Responsibility".


What is it?

The Chain of Responsibility is a behavioural pattern, as it is used to manage algorithms, relationships and responsibilities between objects. According to GoF, the formal definition is

Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.

Software development teams often use in-memory caches to improve performance. They want to speed up access to, or reduce load on, a backing store (database, file system, etc.) by keeping some or all of the data in memory.


You should implement a system in the simplest way. Then after performance testing, you should optimize only when necessary. The reason for this is that performance optimizations make code more complex and may introduce defects. Often these defects are subtle, difficult to find and expensive to fix.


Developers often do not consider thorough testing of caching optimizations. They consider a cache as an implementation detail rather than functionality requiring testing.


A write-through cache approach writes to both the cache and the backing store at the same time. A service can use this approach when it is the single source of the backing store data in a system.


I recommend that you consider the following items when designing, implementing, and testing caches. I have seen live defects in almost all of these areas.


You need to have enough memory for the cache. What is the size of each object in the cache? What is the maximum number of objects in the cache? Do you have enough memory on your machine or JVM when the cache is full? What happens when the cache is full and you need to add one more object to it?


How is the cache initialized? If it’s initialized when your application starts, how long does that take when you cache the maximum number of objects? Can your application serve requests during initialization? If objects are cached as requests are made, is the response time of the cache miss or write-through transaction acceptable?


Verify that the cache is used. If the cache is not write-through you can request the data, then change the data in the backing store, then request it again and it should not change. Or you could request some data to cause it to be cached, then make the backing store inaccessible, and request the same data.

What happens when the backing store is unavailable? A request for data that is cached should probably return successfully. A request for data that is not cached should probably return an error or degraded functionality.


If the cache is not write-through (some other process writes to the backing store), you may have to refresh the data periodically or on demand. Is it acceptable for the cache to be different than the backing store? How long is it acceptable? Verify that the data is refreshed properly.


Will it hold all of the objects or only some of them? Which object do you evict when the cache is full and you need to replace the item? What eviction scheme do you use – Least Recently Used (LRU), Least Frequently Used (LFU) or First In First Out (FIFO) or do entries expire after a period? Verify the eviction scheme.

In addition, for testing and/or production support, you may need the ability to evict individual objects and/or all objects from the cache. One use case for this is you may want to fix some bad data in the database for a particular customer, then clear the cache just for that customer.


Finally, verify you get the performance improvement you expect. Test it using production traffic patterns. When the cache is live in production, monitor the size of the cache and the hit ratio (when a request finds the object in the cache) to determine if the cache works properly. You may need to make improvements.


I hope you agree with me that caches have a lot of functionality that deserves proper design, implementation and testing.

What is Waterfall Model?
Waterfall model is the classic Software Development Life Cycle method practiced in software development process. As the name "waterfall" describes, this development is flowing downwards steadily like waterfall, i.e., proceeds from one phase to another phase. This process is a sequential process or a linear process where in the output of one phase is input of another phase. So previous phase becomes important to be completed before we move to next phase.
Here is the diagram that describes all phases of waterfall model.

Requirement Gathering and Analysis Phase: This is the first phase where requirements to produce a product are gathered and analyzed. This is the phase which involves customer. All information about the entire process are identified to be designed and delivered here.
Design Phase: The requirements from the earlier phase are documented and converted into technical design. Like what hardware, system software, technology, language are used etc. are specified.
Implement Phase:  Output from Design phase are used and implemented to achieve the goal. They are split in program units. These program units are developed independently and functionally tested. This is called Unit Testing.
Test Phase: Here all program units which are developed in implement phase are integrated and tested together to see end product has all desired functionalities required.
Deploy Phase: Once …
The CRUD Functions
CRUD, meaning "Create, Read, Update, Delete" is a common term to data base developers.  It describes the essential functions of data base table maintenance.  This article lays out a minimum example showing how PHP and MySQLi work together to create a table maintenance script.  Of course you could use phpMyAdmin and get a lot more capability, but this is intended to be a teaching example showing the moving parts.  It can also serve as a model for maintenance of any table, with the classic example being a personal address book.  We will use just the names from our address book in this example, but it would be very easy to add other columns for email, phone numbers, etc.

The CRUD functions map to the SQL query commands more or less like this:
  Create = INSERT
  Read = SELECT
  Update = UPDATE
  Delete = DELETE

The HTTP Requests
In our scripts we will use both GET and POST request methods.  HTTP protocols tell us that GET can only be used when there is no change in the data model, therefore we will only be able to use the GET method for scripts that use SELECT queries.  The other three functions will require us to use POST method requests.  The method we use will be identified in the HTML form tag, via the method attribute.  If the method attribute is omitted, the assumption is GET.  If the action attribute is omitted, browsers will submit the request to the current URL.

GET is considered both safe and idempotent.  POST is neither.

Before You Read The Article
Please make sure you understand these two concepts: Variable Scope and Property Visibility.  And to save time later, you might want to bookmark the official PHP explanation of References.  However, please be aware of the age of some of the comments in the web site.  The PHP object model has evolved considerably over the years, and the older comments may not reflect the true behavior of the current stable release.

Variable Assignment
In procedural (non-object-oriented) PHP, variable assignment takes place with the single equal sign.  When a variable is assigned this way, the contents of the variable named on the left side of the equal sign is replaced with the contents of the expression on the right side of the equal sign.  For example, the code below assigns the value of 3 to a variable named $x, then the value in $x is assigned to a variable named $y.  At this point in the script we have two variable containers that are separate and distinct.  A change to either $x or $y will not affect the other variable,  This is simple, straightforward and a common-sense example.
$x = 3;
$y = $x;
var_dump($x); //  int(3)

Open in new window

If it always worked that way (like in Java) that would be fine with me, but PHP has a few "wrinkles" in its variable assignment.  To understand this better, you need to think of a variable name as if it were a pointer to a box.  Whatever you put into the box, can be retrieved or changed by making reference
LVL 111

Author Comment

by:Ray Paseur
@kaufmed: Excellent point!  The __clone() man page says this:
When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties. Any properties that are references to other variables, will remain references.  Once the cloning is complete, if a __clone() method is defined, then the newly created object's __clone() method will be called, to allow any necessary properties that need to be changed.
Possibly the __clone() magic method could be exploited to accomplish deep copying when that is the desired outcome.  A good explanation with examples in different programming languages is available here.

Expert Comment

I googled
ray paseur reference clone

that this question was made for me.

I copy pasted all the code blocks because I am doing a tutorial which uses the words reference and clone
So I am re learning all the Ray code.
Ever wonder how to "do" object oriented programming (OOP)?
LVL 15

Author Comment

by:David L. Hansen
Quite right Doug.  Thanks for your thoughts!
LVL 15

Author Comment

by:David L. Hansen
One of the most frequent problems a "newbie" developer may encounter is having to deal with different data formats. One for all: THE DATE

We, as humans, need to "see" a date and then interpret it (much of the times this is an automatic operation).

What if I show you: "07/05/2013"?
Many of you would certainly recognize it as July 5, 2013.
For just as many (like me), the same format would mean May 7, 2013...

The problem arises from the fact that the format in which this date is shown (and recognized) varies according to the origin and culture.

Human thinking is really far from my field of study, but for sure different contexts lead to different solutions.

Since (until proven otherwise) machines do not think, we should not expect that machines too have our same problems.
We should limit our programs to only "show" a certain type of data (in this case a Date) in the format expected by the user (because the user is human and prefers a format applied to the type). We should have in mind that date formats are solely for our own interpretation.

Machines don't really need "a format", they understand dates (times) as a number stored in a date/time column.

Since we could consider formatting for "show" only, then this is an exclusive operation of the user interfaces.

Everything else, that does not concern the user, MUST NOT have to deal with the formatting of dates.

LVL 111

Expert Comment

by:Ray Paseur
The ISO-8601 standard provides guidance about DATETIME representations.  If you use PHP (or even if you don't) this article may be helpful.
LVL 13

Author Comment

As Ray_Paseur said, ISO is a representation of a type.
That can be used (and I suggest to) when using a strongly-typed object (date/datetime) is not possible, or we have legacy procedures that were designed to use strings or numbers to work with dates.
But ISO is for sure not a "format for humans".
No one of us, if asked for the today's date, would reply as "today is 2013 july 17".
Anyway, if one should choose a format (rather than a specific type) to be used in a program or in any computer procedure, then ISO is for sure the best one.
In fact it is also suitable for sorting purposes, since all the elements' weight are progressively lighter (year, then month, day, hour, minutes...).

That said, what you see in my article is purely my thinking, a "pattern" I pursue.
Anyone can have its own.

And, lastly, there are always exceptions to all said above.
There are procedure where you may find better to use "formats", rather than typed-data.

Foreword (May 2015)

This web page has appeared at Google.  It's definitely worth considering!

How to Know You are Making a Difference at EE

In August, 2013, one of my colleagues posted this, and it made my heart glad.

Grading Comment:
Thanks so much Ray!  I actually haven't posted in a while because at your suggestion I got a few books and spent the last couple of months reading and learning and it's made a world of difference, so thanks a ton for that suggestion as well!

"And by the way,... I am New to PHP"

So many PHP questions at Experts-Exchange include (or should include) that statement that it got me thinking about how to advise new programmers on ways to begin learning PHP.  The popularity of PHP is undeniable; it powers an overwhelming number of web sites, from the very smallest to the giants like Facebook, hundreds of thousands of WordPress blogs, and everything in between.  So it makes sense that any web developer would need to have some foundation in the PHP language.  And for many novice programmers, PHP is the first language they try to learn.

PHP came from humble beginnings; it was originally captioned "Personal Home Page" and was intended to be a language so easy to use, that "even Grandma could learn to use PHP."  And that was fine in the 1990's before the advent of object-oriented programming, hackers, spam, and web services.  But the online environment has grown up and PHP has been forced to grow up, too.  Today, while PHP can still perform simple tasks, PHP can also power enormous database-driven applications that build online communities and analyze mountains of information.

My favorite description of PHP, disarming in its elegance and simplicity, is "What PHP can do is convert a static website that has content that has to be changed by hand into a dynamic one that can display content based on any criteria you can think of."

Getting started with PHP can be daunting, especially if you do not have a background in computer science.  This article will give you some learning resources to get the background you need and will introduce several popular and effective ways to learn PHP.  But there is something you might want to read before you finish this article.  Every professional programmer I know thinks that this is an article of wisdom.  You can take it in if you have seven minutes.  Then come back and finish this article.

Getting the Right Foundation

If you really want to be a professional programmer, you probably want to go to college to major in computer science or electrical engineering.  Almost every major college and university teaches these subject, and the principles are not very hard to learn, but it takes time and practice to turn the learned principles into praxis.  Even if you're not sure about making a career in programming, if you're read this far you probably want to consider taking an Introduction to Computer Science class.  Fortunately, these classes are now available online, for free, using the same syllabus, curriculum and learning materials that the colleges use.  

As but one example, here is what M.I.T. offers:

If you're serious about learning programming, you will need a little math (but not very much).  This series of video lectures will give you a good foundation.

Learning to Think Like a Programmer

For a variety of reasons, you're unlikely to find a basic computer science class that teaches PHP.  PHP is "easy" and these classes are for scientists who like things hard (I'm only joking a little bit).  Expect to find C, Python, Java, JavaScript and similar highly structured programming languages in the beginning classes.  Don't worry about that -- every programmer who achieves anything noteworthy has written programs in many different languages.  The ideas from one language or another bring about a level of intellectual cross-pollination that helps you think about problems from different perspectives and map problems onto different computational frameworks.  And at the most basic levels, all programming languages share many common aspects.  The greatest difference is the written syntax we use to express our ideas.

Do Not Waste Time on Non-Working Code

A programming language is a tool that builds a sequence of instructions.  The instructions tell the computer what we want it to do.  For almost everything you might do with PHP, the thing we want the computer to do is manipulate data.  Each programming problem can be defined and understood in terms of an input and an output, with the computer programming being the intermediary that transforms the input into the output.  If you think about that for a little while, you will come to the same conclusion that almost every experienced programmer comes to: it does nobody any good to post code that does not work.  Instead define and post the data and you will be amazed how quickly you can find clear, easy-to-understand answers.

Expect to Spend a Lot of Time Debugging

You will find that you're human and the computer is not.  Problems expressed in human languages are turned into solutions expressed in computer languages.  This process is full of ambiguity, double-meanings, and confusion.  Humans share culture, but computers require precision at a sub-microscopic level.  Even a single character out of place can render a computer program useless (or worse, destructive).  It's very rare that a programmer can write more than a few lines of code without introducing an unwanted element.  The process of correcting and removing these unwanted elements is called "debugging" and until you have several years of programming experience, it will consume most of the time you spend programming.  More about programming and human factors, as well as many interesting observations from the trenches is available in Jeff Atwood's writings.

Deconstruct Problems Until They Are Small Enough to Solve at a Glance

Complex programs are made up of simpler programs, and simpler programs are made up of even simpler programs.  A mental process of deconstructing problems underlies all programming activities.  As you learn PHP, you will find that you deconstruct complex problems into several smaller problems that are readily solved using PHP programming solutions.

You may have heard of the phrase, "Hello World."  It is the name given to the simplest example of the solution to any programming problem, and it demonstrates success in some small aspect of building a more complex program.  In PHP, the "Hello World" exercise looks something like this.


<?php echo "Hello World.";

This simple PHP script proves that PHP is installed correctly and that it can produce output that is visible on a web browser.  More importantly, it removes many elements of confusion and ambiguity.  What if this script did not work?  Where would you look for a solution?  What symptoms of failure could you find?  Who can help?  All of these uncertainties and doubts impinge on the process of debugging.  And thus we come to the first and most important part of thinking like a programmer: Make the larger problems smaller by reducing each of the larger problems to a collection of smaller problems.

Do this iteratively until the smaller problems are so small that the solution is obvious.  The small solutions then become the building blocks of the larger solutions.  As you construct larger solutions from smaller building blocks, you will hide the details so that the result works like a vending machine - providing useful services to many clients (either programs or people).  Programmers often refer to such self-contained units as a "black box."

Learning the Language of Programmers

A shared culture has a shared language and many terms of art.  You can learn something of PHP without knowing much about general purpose programming, but your learning will be faster and easier if you understand the language that programmers use.  Many familiar words assume new meanings.  For example, the word class takes on a unique meaning when it's applied in the context of computer programming.

I am not suggesting that you need to read or memorize every term of art (a professional will) but you need some good references that you can use to look up words that are unfamiliar or are used in unfamiliar ways.  You might want to take an afternoon to browse these glossaries.


Henson's Glossary

Cal State CS202 TechTarget Programming Words

Learning the Techniques of Programmers

All good programmers have been forced at one time or another to research a subject that they know nothing about.  They have to find out numerous details (too many to remember) and develop code that handles these details.  It's a huge exercise in short-term memory, and it's a huge investment of time.  You wouldn't want to have to do it over again.

Unfortunately, some programmers are condemned to do it over and over again because they didn't write the code clearly, or they used thoughtless variable names, or they left out the comments.  And when they need to reuse that piece of code, they find themselves looking at it and wondering things like, "Did I test this enough?" or worse, "What was I thinking?"  You can avoid this problem by following a few simple rules.

Before you begin writing code, learn the "PSR" basics.  These are valuable standards.  They will make your programming easy to read and understand, and they will make your code look professional (highly valuable if you want to get a job as a programmer).  Here are the two links you should study.

1. Whenever you're required to solve a problem that you have never solved before, make a teaching example from the solution.  Collect a library of these.

2. Whenever possible use meaningful variable names, eg, if the value is "Today's date" name the variable $today instead of something useless like $x.

3. Use comments to say what your programming is intended to do.  Often you will find that simply writing the commentsfirst, before you write a single line of code, will help you consolidate your thinking.

4. Test iteratively as you build the code.  Don't write more than a few lines without testing.  Use the principles of Test-Driven Development.

5. Programming is all about the data.  Learn about var_dump() and make regular use of it!

6. Avoid copying code you find on the internet, especially code that has a lot of compound statements.  Instead of copying, deconstruct the code, taking a moment to ask, "why?" and rewriting the code in your own words, with your own explanatory comments.

7. Adopt a coding standard and adhere to it rigidly.  With discipline comes great power.

Learning How to Get Help: the SSCCE

Anyone who says he is a self-taught programmer is missing something.  You cannot make this stuff up - you have to learn it from a variety of sources, and one of the most important sources is the community of programmers who surround you.  Perhaps you're in a university class where you can learn from your colleagues and classmates.  Or perhaps you're a regular at Experts-Exchange and Stack Overflow.  In any learning community you need to know how to share ideas with others.  That's where the SSCCE comes in.  If the only thing you take away from this article is the SSCCE, it will have been worth my time to write it and worth your time to read it.  Follow the link, read the page (there is only one page) and embrace the principles!  The SSCCE is not alone in the universe, other authors have given voice to the same concept: a problem well stated is a problem half solved.

Think about the data - what do you have for input and what do you want for output.  Try to assemble that information before you ask the question.  Then you can say, "Here's what I've got and here's what I want."  That makes for a clear problem definition.  Clear problem definitions will save you an amazing amount of time.  As Charles Kettering said, "A problem well stated is a problem half solved."

Try to avoid complicating the situation with an unnecessary explanation, when an input/output example could be used instead.  This is an actual quote from a question posted here at EE: "take that number, split it into an array. so 25 would become [2,5], or 12 would become [1,2] then use those to determine which image to show in the basket count, then loop the array to determine which images to show"  What's the author trying to say?  Your guess is as good as mine.

Learning PHP from

Now that we have introduced the deep background stuff, and shown you how to frame a problem and ask for help, it's time to get into the part of this article that is about learning -- and using -- PHP.

A good place to start is with, where you will find the best online technical documentation in the world.

If you do not read the online documentation, you're robbing yourself, stealing valuable time from learning.  Instead of learning from the experience and writings of others, you'll be learning by trial and error, maybe from reading other people's programs.  That takes longer.  A lot longer.  And it's full of risk.  Trying to learn programming by trial and error is like trying to learn to bake by looking at an apple pie.  Sure you can appreciate the finished product, but looking at a pie will tell you nothing of the other ingredients, the processes and the tools used to make the pie.  Likewise, a finished program tells you nothing of the thought processes of the developers, nor of the assumptions they made or the test data they used.  So don't try to learn that way.  Instead, exploit the web site for all its worth.  Here is how.

New in 2014: PHP has an About the Manual page, including How to Read a Function Definition and links to Support for New Users.

PHP has a "getting started" page.

PHP has an introductory tutorial.  No excuses -- Just Do It!

PHP has an omnibus FAQ page.

PHP has its entire manual online!

PHP has its own Security page and it is required reading, no excuses!

PHP has the language reference online.   No excuses here either.  You must read these sections and every one of the associated links:

Basic Syntax






Control Structures


Predefined Variables

If you want to move beyond basic PHP programming and begin collaboration with others, you want to read these sections, too.

Classes and Objects



If you want to interact with software or data on other servers you need to read these sections.

Context Options

Protocols and Wrappers

If you want to learn from the collective wisdom of others, these FAQ pages are very helpful:

Using PHP


PHP and Databases

Part of what makes so valuable is the function reference.  PHP has, at this writing, over 1,500 built-in functions.  You can't memorize all of them, so you need a quick way to refer to them.  When I am programming I have a window open to at all times.  If you know the name of the function you want to use, just type a URL like this: and PHP will find the date() function.  Couldn't be easier!  And the magic doesn't end with the official PHP documentation.  Every function page has a section for user-contributed notes.  Often, seeing the way others have used a function (or learned from an unpleasant surprise) will give you great insights into the richness and power of the PHP language.  For example, see this:

If you don't know the name of the function you want to use, you can find the function reference table of contents.   Don't plan on reading all of this.  You might want to bookmark it.

The parts of the function reference that you want to read first are probably these:


Database, especially MySQL

File System







Learning PHP from Books

One of the really great things about tech people is that they like tech features, for example, the ability to write book reviews on If you find a popular and well-reviewed book (and it's not too old) it will probably make a valuable addition to your technical/professional library.  You can't have too many PHP books!  Here are some of the books that I own and recommend.  If you decide to get any of these, be sure to look for the latest editions, because PHP is a living language.

Beginner: Yank Ignore the hokey title -- it's a good book.

Beginner to intermediate: Welling/Thompson

Intermediate to Advanced: Powers

Intermediate to Advanced: Ullman

Advanced: Zandstra

Learning PHP from Online Resources

Most of these resources are 100% free:  Almost anything about PHP from SitePoint is worthwhile.  There are good introductory references at Tizag and W3Schools, however the Tizag PHP web site appears to have gone out of date.  Many of my students swear by CodeAcademy.  And of course there is a Wiki:

New in 2017: Stefan Priebsch curates this site on Software Craftsmanship (advanced)

New in 2016: Jeffrey Way brings his considerable teaching skills to a set of PHP courses here:

While you are mastering the basics of PHP you will have many questions that others have had before you.  This is a worthwhile resource for many of those questions.

Once you have mastered the basics of PHP, there is an excellent online resource from the authors of the Slim Framework.

A set of paid courses on PHP is available from  It is not clear to me whether these are up-to-date.

A set of paid courses on PHP, from active PHP experts, is available from PHP Architect.  The company also publishes books and newsletters, and runs conferences covering PHP topics from the most introductory "bootcamp" to advanced object-oriented design.  If you want to learn from the best in the business, this is the place to come.

Learning PHP from "That Guy" -- NOT!

You've heard the expression, "Don't be that guy."  I'm going to add a recommendation here: "Don't learn PHP from 'That Guy'."  The internet is littered with examples of terrible PHP code.  Mostly it's code from half-taught programmers who don't understand the principles of computer science, don't understand the principles of programming security and don't take the time to clean up after themselves.  It turns up in forums all the time.  It may be untested.  It's almost always undocumented.  And it's something you would use at your own peril.  It's usually worth exactly what you paid for it!  So just say "no" to that stuff and stick to the links published here.  It will save you a lot of grief.


Don't feel awkward or embarrassed if you're new to PHP.  Ignorance is no sin and we were all new to the language once.  Instead, embrace the learning resources documented here, build your own personal library of code examples, post plenty of PHP questions at Experts-Exchange and most importantly give yourself time to work with the language, so that you become familiar with the commonly used parts.  The gift of time and study is one that only you can give yourself, and it may be the most valuable gift of all. And if you're doing it right, learning PHP is fun.

Welcome to PHP!

Please give us your feedback!

If you found this article helpful, please click the "thumb's up" button below. Doing so lets the E-E community know what is valuable for E-E members and helps provide direction for future articles.  If you have questions or comments, please add them.  Thanks!


LVL 85

Expert Comment

by:Dave Baldwin
Another thing that I have had to almost beat into some people's heads is that you can't 'logically' figure these things out.  While computers at the lowest levels operate logically, the things that people actually deal with like programming or even just using a program are based on the Choices made by someone somewhere.  You can't logically out-guess the choices made by someone else, you need to look them up in the documentation and find the rules that apply.  

The PHP developers are constantly trying to make function calls as uniform and predictable as they can... but there are a lot of things that have slipped in over the years.  And another truckload of things that are simply non-obvious.  Even those of us who write PHP code virtually every day have to do that.  People pay me to fix and modify other people's PHP code.  Like Ray, I have a browser window open to almost all the time.
LVL 111

Author Comment

by:Ray Paseur
@DaveBaldwin: Yes, that is the way!  Just look at an apple pie and see if it can tell you how to bake an apple pie.  It's the same with any recipe and the same with computer code.  There is not always a light unto my feet and a path before me unless I care for the details along  the way.
An individual new to programming usually falls into one of two classes;


Passionately obsessed with learning and willing undergo immeasurable amounts of sleep deprivation to learn this new skill, or


Approaches learning programming so unprepared that the immediate disappointment and frustration quickly consumes any desire that they had going in.
I would like to take this opportunity to present a "primer", of sorts, that I believe will allow just about anyone to turn this venture into a much more satisfying undertaking. But before we start, I'll preface this with a few qualifiers:
Language: PHP 5.x
Skill Level: Entry
Logical Reasoning Skills: Mid to High
Frustration Tolerance: Mid-level

If you can honestly assess yourself as being in possession of the three latter bullet items, you will likely find this article of great advantage to you. If not, then save yourself the frustration and abandon it altogether or continue reading for the simple sake of reading something.

    PHP is remarkably flexible language. Due to the fact that it lacks the more strict rigors such as variable type declarations as well as also having a much cleaner syntax than languages like C or C++, it certainly allows for a pleasantly shortened learning curve.
    Of course, one of the downsides to this is the fact that it also has the …
LVL 76

Expert Comment

In your preface, paragraph 2:

"Of coarse, one of the downsides..."

"coarse" should be "course". In paragraph 3:

Likewise though, don't let...

"Likewise" and "though" are redundant. Choose one or the other.

In paragraph 2 of "Programming 101":

"...a sign of a really good programmer or upcoming programmer..."

...I don't think "upcoming" is the right term to use here. I would drop that bit altogether and just say, "...a sign of a good programmer..."

In paragraph 3 of that same section:

(or in Agile terms, stories)

...if your target audience is someone new to development, they probably don't have a clue as to what Agile development practices are. I wouldn't introduce that term without explaining what it is--which seems outside the scope of this particular article.

I think the topic and goal you are attempting here are good, but you need to be careful. You are discussing the general topic of "programming," but you are demonstrating more of a procedural programming paradigm. You might consider mentioning that programming encompasses many different paradigms, and describe which paradigm you are introducing the reader to.
LVL 12

Author Comment

by:Richard Davis
I most certainly will make the grammatical changes that have been suggested as I am not formally versed in the intricate ins and outs of grammar. Albeit, I do my informal best to be a correct as possible. So, that critique is greatly appreciated.

Although, I see your point about the focus of the article and the implied value therein, I would like to present that as for the requested expansion on the particular paradigm I am focusing this article around; the intention was not to pidgin-hole the context to any single paradigm, but rather to address a more generalized mindset of how a beginning programmer might need to analyze real-world scenarios. Therefore, that mindset eludes specificity in favor of the more broad spectrum of programming mentality.

Admittedly, certain presentations in my article fall into a procedural paradigm, I chose that particular direction as it's the easiest for someone new to programming to grasp versus more advanced structures like OOP.

If you truly think that my article ultimately does require that change and that it will provide more benefit, I have no problem making the requested modifications for the reader's sake.

Thank you for the editorial feedback, kaufmed!
The topic of "code smell" is rather fascinating, as well as rather "geeky". Is it better to learn from one's own mistakes while developing in a new programming language, or, seeing the coding mishaps of someone else?

Here are some interesting points of "code smells" that most OOP (Object-Oriented Programming) "noob" developers could probably use to get better at Java / OOP PHP.

Great examples of code smells are realized when a developer is tasked with having to go back and rework multiple developers' code for a maintenance and upgrade project for an employer. A common example might be a Web Portal that POUNDS on a SQL database by taking field level values of a result set of a SQL query, and creates new queries from that result set, and sends NEW queries on different JOINed tables/views to produce reporting. The database servers capacity and internet pipe might be PATHETIC for what the company is trying to accomplish, so imagine optimization is rather critical in this case. The "too many cooks in one kitchen" code was thrown together to make an impossible deadline, and with little to no business requirements. It is a disaster to unravel... BUT... it somehow work! Even though, it is still slow during peak usage times, but fully functional for the most part. Does it have a bunch of bugs? No... not really. It likely just lacks design, structure and consistency and n serious need of some "code deodorant".

Yes, you heard it right! In this article, I am going to explain why it is so (in as many ways as possible). Now, if you are a IT Project Manager or a Technology Architect who has used the term 'building an intelligence in this software' with the client or in front of a developer, and you get pissed off easily when someone challenges your usage of IT terms, then you need to quit reading right now.

What is intelligence?
Intelligence is the ability to take a decision in the unseen, unfamiliar, and unvisited circumstances. How good/effective your decision is, decides how intelligent you are. For example, consider the situation of joining a new office at a new place. You haven't asked for the directions to the office and only know the address of the office. You need to make some decisions now which includes, from where to take the bus, how long to wait for the bus, which bus to take, how much cash/change to keep with yourself, should I be consulting someone for the information, from whom to check this information, etc. There will be tons of decision you will take when you will be in a new situation. Most likely your decisions will be based on not only HOW, but it will include WHY and WHAT too. Next time you will have fewer decisions to make, or may even some new ones like should I take taxi instead to save time, is there another bus that can take me to my destination in lesser time, etc.

How a software behaves?
Your application software is nothing but a …
LVL 19

Expert Comment

Hi Gurvinder

Thank you for taking the time to write a though provoking article about this topic. Nothing you have stated is untrue but I think you are taking a very wide view of 'intelligence' and pointing out, quite rightly, that current software cannot emulate that.

I would be interested to know how you would separate 'standard' software that operates in the manner you describe from 'intelligent software' such as that which adapts its function over time - eg: Amazon tracking your buying habits and recommending a new book or phone apps that monitor locations and establish alternate commute routes. I agree that these are not 'intelligent' by your definition but I can also see why a marketing user might want to find a word for such behaviour that the public would understand. Also where do you see fuzzy logic, genetic algorithms and the recent news article where a robot demonstrated 'self awareness' when asked a question recently?

Your point about debugging intelligent software is an interesting one, but if we actually managed to create a self aware, thinking application I doubt that debugging it would be the first concern - I'd be too busy collecting money and plaudits :)

LVL 40

Author Comment

by:Gurvinder Pal Singh
@regmigrant, thanks for your comment,

I would be interested to know how you would separate 'standard' software that operates in the manner you describe from 'intelligent software' such as that which adapts its function over time - eg: Amazon tracking your buying habits and recommending a new book or phone apps that monitor locations and establish alternate commute routes.

As long as Amazon has coded the software to take specific decisions based on specific buying patterns (their own interpretation of buying habits), it is just like any other program which is hardwired to take specific steps rather than think on its own. It is not intelligence since the code is adapting to habits just the function is based on how it has been coded.

I agree that these are not 'intelligent' by your definition but I can also see why a marketing user might want to find a word for such behaviour that the public would understand

Totally get the marketing compulsions and its appeal in sales pitches, but should be kept out of engineering discussions. It could be confusing as hell for the developer and may end up complicating the matter more than required or intended.

Also where do you see fuzzy logic, genetic algorithms and the recent news article where a robot demonstrated 'self awareness' when asked a question recently?

These implementations (assuming they are implemented) to make software's decision making as close as possible to real life's decision making. Would like to see that 'self-awareness' video of the robot, thought :)
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit and similar technologies have enjoyed wide adoption, making it possible to write and share unit tests among teams of programmers.  Behat and similar technologies (Laravel, for example) have introduced fluency into the programming process.  Taken together, these advances have brought open-source programming into a state that is somewhat similar to musket making, just after Eli Whitney.  If you're here looking for guidance about modernizing your development process, please take some time to learn about these "new technologies" because you will soon be unemployable if you're not conversant in the details.  These are the greatest advances in software development in our generation.

Now back to our Test-Driven Development article...

On Monday, October 17, 2011, the A.Word.A.Day "Thought for Today" was "A problem well stated is a problem half solved." -- attributed to Charles F. Kettering, inventor and engineer (1876-1958).

The Greatest Handicap a Programmer Can Have
The author of a question here at EE wrote. "I have no test data besides some stuff I can come up with."
LVL 85

Expert Comment

by:Dave Baldwin
That exactly corresponds to the date problem.  For whatever reason, the end-user is allowed to enter an unacceptable format.  If it was on my web page, I'd make it a drop-down or radio boxes that only allow the proper formats.  Like I said above, let the salesman test it, they always get it wrong.
LVL 52

Expert Comment

Ray, you write so well and with passion, another impressive article. I have an admission to make however, my "eyes glaze over" when I see regex patterns :)

I'm also led to wonder why on earth we allowed things like .com without a geo reference first up, and that the sequence wasn't "top down". That is why is the Top level domain last? :) Heaven knows what will happen with TLD's in the future too (e.g. generic names)  - be prepared for regular revisits.

Such is life.

Programming without test data is the practice of clairvoyancy.
Pretext and Context

In previous article, I designed the data model of a basic Identity Management System. In this article, I will enhance the scope and boundaries of the system to make it a workflow based system. In the process, new entities and relationships will be introduced and some changes will be made to the existing entities and relationship between them, which were designed in previous article.

Scope and Boundaries
Identity Management System (IDM) is a system meant to manage the indentity of users in external systems. Apart from the scope mentioned in previous article, additional scope includes:
identity management is workflow dependent now.
System will have its own defined users, and will be managed by the system itself.
Other features of the system are:
management is not based any variable like time, event, etc .
No policy-based identity management for other systems.
management of its own system users will be workflow based now..

Lets understand Workflows in System

To understand what is workflow in a system and why it is important to manage for IDM system, lets visualize this. IDM system receive a request for the verification of an identity
Pretext and Context:
In this series, I wish to design the data model of systems in question. I will start by defining the scope and boundaries of the system, followed by subsystems involved, then finally the entities in those systems and subsystems. System in question is either made up based on real-life experiences or something that I might have heard before somewhere. Scope and boundaries of the system will have the definition and the different functionalities and roles in that system.

Scope and Boundaries:
Identity Management System (IDM) is a system meant to manage the identity of users in external systems. Scope of managing the identity ranges from usual CRUD (create, update, retrieve and delete) to other activities like:
managing the user's role and permissions (basic CRUD)
verifying user's permissions against an data entity or screen interface attributes

Other features of the system are:
management is not based any variable like time, event, etc
No work flow is involved; request for management, its review and approval is out of the scope.
No credentials required to use the system

Entities in the System:
Before I jump on to the entities in this system, let me specify (for the sake of clarity and better understanding) the different elements of the system
Equipment Elements:
LVL 30

Expert Comment

by:Mayank S
What is the business area that we are targetting here? Something like social networking? And if that is the case, then my second question is that what is the difference that we are highlighting in this system compared to what already exists in the market?
This article explores the difference between two entities: List and Category.   In part one,  we'll look at the basic concepts, and set some groundwork.  In part two, we'll get to some conclusions.

I know that these two things are different, but I need to find out a method using which I make my software program identify the distinction.  I am trying to be methodical.  After a search/research and brainstorming for some hours, I am able to come up with this much:

A List is a collection of items.
Properties of a list:
name of the list
list of items
list of sublists
A Category is a class or division in a scheme of classification.
Properties of a category:
list of items
list of subcategories
While I am aware that List and Category are two different things or entities, I am not able to find one attribute in any of these entities which is not in the other one.  So, I am unable to see the difference either due to:

My inability to describe the entity in terms of its attributes, or...
It is impossible to describe an entity in terms of only its attributes and something else is required, or...
The difference in entities is not because of the difference in attributes.
I have made two assumptions so far:
It is possible to compare entities.
One of the way to do so is to compare the properties and behavior first.
There are some questions to be asked which challenges the assumptions first.

How do we compare two entities?
LVL 40

Author Comment

by:Gurvinder Pal Singh
Thanks for your interesting analysis.
Yes, it definitely is tricky to compare the real world entities in terms of properties, but that was the one of the main points I wanted to convey in this article.
We were told that looking at the real world in terms of data (something that OOPs claims to do), is the best way forward. It is suppose to give us clearest picture of the real world entities. But, it clearly is not, if we have to compare multiple entities with each other, which is often the confusion while designing a OOP-based design.

However, if you ask me where it is useful, i would say if a breakthrough can be achieved in this, it can revolutionize the soft-computing altogether, since we don't have to embed the logic of comparing with explicit set of entities. Otherwise, if you really look at it, if right now if a Robot is asked to tell if a particular object is Dog or not, he cannot since he is most likely to judge the same based on the properties of that object. Isn't it?
LVL 29

Expert Comment

I think that's just it Gurvinder - if you asked a Robot in 1990 "is this a dog?" it would check the list of properties for a dog and compare it to the properties of the object in front of it.

But if you asked a Robot in 2011 "is this a dog?" it would compare it to the thousands of other instances it had seen before with the label of "dog" and decide if this current object was close enough to those others.

This is (in very approximate terms) is how Watson played Jeopardy and did so well.

I'm not sure what that really means for OOP since we are living in the land of rules, but I do think it goes to the core problem you're considering and why OOP doesn't always do as well as we might hope.


Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.