Aug 10

Echo vs. Print

The most common way to output text with PHP is using echo or print. In this section we will see the similarities and the differences between them.

Similarities

  • They are both language constructs (not functions) so by all means drop the parentheses:
    <?php
        echo 'foo';
    
        print 'bar';
    ?>
  • They can be used to output multiple lines:
    <?php
        echo 'This is the first line.
        This is the second line.';
    
        print 'As you can see,
        it works with print, too.';
    ?>

Differences

  • print returns 1 so it can be used as a function:
    <?php
        (1 == 1) ? print 'true' : print 'false'
        //Outputs 'true'
    
        (1 == 1) ? echo 'true' : echo 'false'
        //Doesn't work
    
        echo (1 == 1) ? 'true' : 'false'
        //Outputs 'true'
    ?>
  • With echo you can “concatenate” with a comma.  I put concatenate in quotes because it looks and feels like concatenation is happening, but it’s not actually concatenation.  I’ll talk about that more later.
    <?php
        echo 'With echo you can ', 'use the comma ', 'to output multiple parameters.';
        //Works
    
        print 'With print ', 'you will get ', 'an error.';
        //Doesn't work
    ?>

Realistically there is no real reason to prefer print over echo unless you want to use it as a function.  Give me a solid case for this usage and I’ll bend, but I’ve never needed to use it.  echo can do all the things that print does better: it’s slightly faster than print…and it’s one less character to type!

Dots vs. Commas

As I mentioned earlier, you can use both dots and commas to output strings and variables using echo but with print, you can only use dots. So, what’s the difference?

When using dots, all the parts are concatenated to form a single string that will then be printed, while with commas, all the parts are printed individually, and although the end result appears to be concatenation, each item is actually output one-by-one.

This actually makes the use of commas slightly faster than using dots because the string concatenation is skipped but the end result is exactly the same – no spaces will be added between the arguments (like in Python) – so commas are the preferred method for outputting multiple string segments and variables with echo.

<?php
    $var = 'foobar';
    echo 'The value of $var is ', $var;
    //Output: The value of $var is foobar
?>

Single Quotes vs. Double Quotes

In PHP there are two main ways to specify a string: single quotes (’foo‘) and double quotes (”bar“).  There’s also a couple more ways — heredoc and nowdoc — but I don’t want to get into that can of worms here.

Single quotes

When you need to output a plain string, the single quotes are probably the best idea.

Variables and escaped characters (e.g. \n, \t, \" etc.) will not be expanded, except for \' and \\ (you can also write just a single \ to output the backslash). This will make the parsing of a single quoted string slightly faster than a double quoted one, and you don’t have to escape double quotes (e.g. in HTML attributes) as we can see in the following examples:

<?php
    echo 'This is a plain string';
    //Output: This is a plain string

    $var = 123;
    echo 'This $var and this \n newline character will not be expanded.';
    //Output: This $var and this \n newline character will not be expanded.

    echo 'The \' single quote and the \\ backslash will be expanded.
    The single \ backslash works too.';
    //Output: The ' single quote and the \ backslash will be expanded.
    //The single \ backslash works too.

    echo '<img src="foo.jpg" alt="test" height="100" width="100">';
    //Output: <img src="foo.jpg" alt="test" height="100" width="100">
?>

Double quotes

If you use a double quoted string, variables and escaped characters will be expanded.

<?php
    $var = 123;
    echo "This $var will be expanded. You can also use \$var if you want to avoid it.";
    //Output: This 123 will be expanded. You can also use $var if you want to avoid it.

    echo "This characters will be expanded too:\nfoo\n\tbar\nbaz";
    //Output: This characters will be expanded too:
    //foo
    //    bar
    //baz

    echo "<img src=\"foo.jpg\" alt=\"test\" height=\"100\" width=\"100\">";
    //Output: <img src="foo.jpg" alt="test" height="100" width="100">

    echo "You can also print characters in octal and hexadecimal notation like \141 and \x62.";
    //Output: You can also print characters in octal and hexadecimal notation like a and b.
?>

Bottom line is that it’s better to use single quotes and avoid to include variables inside the strings.  The only real time you may want to use double-quotes is when you have lot of variables that have to be included in a string.  In this case, the use of double quotes may improve the readability of the code.

Conclusion

  • Use echo instead of print
  • Don’t use parentheses with echo (or any language constructs for that matter)
  • Use single quotes if you don’t have to use escaped characters or need to expand many variables
  • Always use a comma instead of a dot when joining strings and variables in an echo statement
Jul 22

Reducing the Software Development Effort

In Part1, I outlined the techniques Software Development needs to take in order to have competitive wages in the most recent market. In this section I’m going to dig a bit deeper into the summary by highlighting the fact that about two-thirds of the features of a typical software system are seldom or never used. Often, only twenty percent of the features are used frequently and so reducing the requirements as the development process unravels is key to increased productivity.

1. Eliminating extra features that no one really wants is probably the single largest opportunity for increasing software development productivity in most organizations. Extra features are generated by a software development process that attempts to nail down the features in a system at the beginning of the development process. Typically, customers are asked to decide at the start of a project what features
they want. Often they have little incentive to keep the features list short, but they are penalized if any items are forgotten. Can there be any wonder that a feature list generated with such incentives contains far more features than are necessary?

The biggest opportunity for reducing software development effort is to limit overproduction of features by developing features on an as-needed basis. For many companies, this may require a paradigm shift in architecture and design. However, it is becoming increasingly apparent that there are many disciplined approaches to software development that provide for an emergent architecture. In the Open Source community this technique is practiced without much thought. By breaking the development into phases and milestones in an as-needed or prioritized basis is one of the keys to success here. Refactoring the code on an on-going basis keeps the design simple, clean, and efficient while developing test harnesses at the same time as developing the underlying code is a must are also key to this approach.

2. Streamline the Development Processes The measure of maturity of an organization is the speed at which it can reliably and repeatedly execute it’s key processes. A mature software development organization is one that can rapidly, reliably and reliably translate customer needs into deployed code. Too often, rapid software development has been equated with sloppy work, so attempts to streamline the development process are often looked upon with suspicion. However, in industry after industry, when sequential development processes are replaced with concurrent development processes, costs are slashed, quality is improved, and development time is dramatically reduced.

Organizations which record year-on-year productivity improvements spend a lot of time focusing on streamlining key processes while increasing their reliability. They do this by focusing on the flow of value through the process. There are three main techniques used to do this:

a. Value stream mapping is a tried and true approach to streamlining value-creating processes. A value stream map of the current state is invaluable for spotting waste; a value stream map of the desired future state is a roadmap for process improvement. Poppendieck.LLC helps organizations use value stream mapping to improve software development productivity.

b. Kaizen events are a typical implementation vehicle for streamlining operational processes. In software development, a modification of Kaizen events is usually required, because software improvement efforts usually take more time than is generally allocated for Kaizen events. We facilitate effective Kaizen events for software development.

c. An Integrated Product Team (IPT) is frequently used to facilitate information flow across an entire development team. Software development IPT’s involve not only architects, designers and developers,
but also those responsible for deployment, operations, customer support, and maintenance.

3. Increase Customer Value Understanding customer value well enough to obtain additional revenue is the third key to increasing software development productivity. In general, customers cannot be relied upon to tell a software development organization how to increase the value of its offerings. In fact, customers generally think of software as a tool that should adapt to their needs over time. This makes understanding customer
value elusive not only during a software development project, but even after deployment. And yet, the price that can be charged for software is directly related to understating how to increase its value proposition.

We are not likely to increase software’s value proposition unless we increase our understanding how customers might use our software to create value for themselves. There are three steps to increasing customer value:

a. Iterative development with frequent releases creates a short feedback loop between customers and developers. The key to successful iterative development is to prioritize the feature list, implement features in order of business value, and deploy them as soon as possible. The short feedback loop created by iterative development and early deployment not only limits the development of unnecessary code, it brings to light innovative new uses of technology that can significantly improve business results.

b. The next step to understanding customer value is to understand how our customers create value for their customers. Increasing the support of key value creating processes for customers is the most likely source of increased revenue for software development. One method of discovering how our customers create value is to focus on their key processes and map their value stream.

c. The final step to providing customer value is to link organizations through partnerships that focus on the overall productivity of the combined enterprise. Peter Drucker noted in Management Challenge for the 21st Century that “In every single case…the integration into one management system of enterprises that are linked economically rather than controlled legally, has given a cost advantage of at least 25 percent and more often 30 percent.” The bottom line is that when organizations work together for their mutual benefit rather than optimizing the results of the individual organizations, a large increase in overall productivity can be realized.

Software development organizations have always emphasized process; however, the focus has been on predictable delivery of pre-defined scope rather than increased productivity. Not surprisingly, processes which did not value productivity did not deliver productivity increases; quite often they decreased productivity instead. We need to move from processes which define scope early to processes which allow only the most valuable scope to be addressed. We need to move from slow processes with many wasteful steps to streamlined processes which eliminate non-value-adding activities. We need to focus on increasing revenue potential over cutting costs by discovering how we can help our customers increase their productivity.

References
i. Johnson, Jim, Chairman of The Standish Group, ‘ROI, It’s Your Job,’ Published Keynote Third International Conference on Extreme Programming, Alghero, Italy, May, 26-29, 2002
ii. Management Challenge for the 21st Century, Peter Drucker, Harper Business, 2001, p 33.

Jul 21

Productivity is the prime determinant of our standard of living. If the revenue generated
per work hour goes up, income levels go up. If productivity goes down, wages go down.
When all else is equal in a market, the more productive company will enjoy greater
profits. Thus the key to sustaining and increasing wages in the software development
industry is to continually improve development productivity.

Throughout the 90’s, productivity increases in the technology sector resulted largely from increased capability of the underlying technology.  Case in point, faster computers make faster developers because “wait times” are reduced and with newer techniques and APIs it became easier and easier to accomplish larger tasks with fewer lines of code.  In recent years, however, software development productivity has stagnated as demand for newer technology has flattened. Thus it should come as no surprise that wages in the software development profession have flattened and even declined in many cases.

As the technology sector matures, it can no longer depend on increasing growth in the underlying technology to fuel productivity increases. The time has come for serious efforts to be made in order to increase productivity through more efficient use of labor and more effective value propositions for customers. This is how more mature economic sectors have been increasing productivity for decades and it is only fair that the IT industry must follow suit.

First of all, we need to define what we mean by productivity improvement in the software development industry. Traditionally, we have measured productivity as thousand lines of code (kloc) per labor hour. However, the key process of a development activity is taking an idea and making it into a product. To measure the real productivity of software development, we need look at how efficiently and effectively we turn ideas into software.  So perhaps we should start with a new definition of software development productivity:

  1. For companies that develop and sell software as a product, productivity may be defined as the revenue generated per employee.
  2. For internal IT organizations, productivity may be defined as increased revenue realized by the supported business per dollar spent by the IT organization.

There are three basic approaches to productivity improvement:

  1. Reduce product costs by eliminating investments in product features that customers do not find valuable.
  2. Reduce indirect costs by streamlining processes and eliminating inefficiencies in development, delivery and support.
  3. Increase revenue by adding more value to a product so customers will pay more for it.

Tomorrow, I’ll finish up Part 2, where I’ll explore each of the above approaches to improving software development productivity.

Jul 17

It is so common for tools such as Excel to be used for managing customer databases, for keeping track of creditors and debtors, and for organising the flow of business data that many business owners assume their employees are using the right tools for the job.

Whilst many of these tools are excellent for their intended purpose, they are frequently used in lieu of a more appropriate technology, simply because of familiarity with that tool. This is just one example of where a Technical Consultant can provide businesses and their employees with significant productivity boosts.

Jul 15

Technically speaking, a database is a collection of information arranged for ease and speed of search and retrieval. A computerized database uses software to organize the collection and storage of the information and allows a person or computer program to collect any additional information. Simply put, a database holds all your shared information such as customers, contacts, suppliers, product information, and sales history–everything you and your enterprise use daily.

The software used to establish this database is the database management system. iTeam offers customized database management systems to store, manage and retrieve information. These systems offer custom designed software that are most efficient and cost effective for each individual business need.

Most people are familiar with data storages such as OpenOffice, Microsoft Excel and Microsoft Access and use these tools to maintain all of their information. There are pros and cons to systems such as these. For example, unless the information is shared over a network on a server, there is a chance of overlap, double entry and often only one person may access the file at a time. Such systems appear inexpensive because most businesses already have an office application; however they quickly become time consuming when working with more than one spreadsheet. As businesses grow, customizing your system becomes a necessity to increasing business efficiencies, minimizing training and reducing other associated costs.

Business needs vary for each company, an example of some of the forms of customized software include:

  • Increase your employee productivity
    • Reduce your employees paper work
    • Eliminate double entries with automation
  • Increase reporting capabilities
  • Retrieve Real time information for everyone
    • Increase efficiencies
    • Increase customer satisfaction
  • Reduce training time for new employees
  • Access and enter information on your blackberry or PDA
  • Easily import and export information in any format
  • Software enabling access to the database over the internet
  • Create database securities which limit the access of the information
  • Synchronize or auto-generate formulas and/or calculated fields to automatically update your data

Bottom line is: if you are looking for a turn-key system you need something that is easily implemented with minimal training that integrates databases that fit with your business logistics and is either stand-alone or is an enhancement to your current system.

Your business can make improvements to information management in a variety of ways. These improvements can range from small enhancements at a minimal cost, to a complete over-haul of your existing system. Each business has its own separate needs–a customized database system is often the most efficient and can become a cost effective way to manage these needs.

Next Entries »