Terminal / console command from the program from start

The following function can be started console commands from a C / C program:

#include <iomanip>
#include <iostream>
#include <cstdlib>

using namespace std;

bool startExternalProgramm(char* terminalCommando)
{    
    bool returnVal = false;
    if(terminalCommando != "")
    {
        cout << "Executing terminal command: " << terminalCommando << endl;
        int systemReturn = system(terminalCommando);
        
        if (systemReturn == 0)
        {
            returnVal = true;
        }
        else
        {
            cout << "The value returned from Terminal  was: " << systemReturn << endl;
            cout << "Sorry,commando for terminal not executable" << endl; 
        }
    }
    else
    {
        cout << "Sorry, empty commando for terminal" << endl;         
    }
    return returnVal;
        
}

Part 2: Clean Code – correct and incorrect comments

According to the book (Chapter 4):&nbsp; “Clean Code – Refactoring, Patterns, Testing and techniques for clean code” of Robert C. Martin.

“Comment not bad code – write to him.”

(Brian W. Kernighan und P.J. Plaugher)

 

Comments can be both, helpful and hindering:

  • hindrance, if you are outdated and incorrect information supply
  • disturbing, if you are too long and unnecessarily
  • helpful, if you are well placed

The use of comments “our inability to balancing, clear to us in our code to express”(S.85). Before writing a comment, one should consider before, whether the code can not be further written expressive.

more…

Copy Code line numbers delete regex

When copying code from Web pages(z.B. Zend.com) it may occur, that the lines of code containing numbers, e.g..

  1. // Parameters for ClientAuth authentication
  2. $service = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;
  3. $user = “”;
  4. $pass = “pa $ $ w0rd”;
  5. // Create an authenticated HTTP client
  6. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  7. // Create an instance of the Base service
  8. $service = new Zend_Gdata_Gbase($client);
To clear the Zeilennumern, can e.g.. following command to run with Netbeans:
STRG H (SEARCH and REPLACE)
Find what: [0-9]{1,2}.\n
Replace with: (blank)
Select: Regular Expressions

Regular Expressions Netbeans

Part 1: Clean Code – Rules for good, clean code

To write clean code and easy to understand the ultimate goal is a good IT Projet. Much depends on:

  • Maintainability
  • Training time for other programmers, means fast, what do individual functions
  • Robustness to changes
  • Testability, everything falls together, with small changes, can quickly stable updates are
  • Popularity with other programmers e.g.: bei Open Source Projekten, as a negative example is called XT-Commerce

The highly recommended standard work on the subject is “Clean Code – Refactoring, Patterns, Testing and techniques for clean code” of Robert C. Martin. In this article, chapter 1 to 3 treated.

Meaningful names

The name of a variable, Function or class should declare immediately, why you exist, what it does and how it is used. If a variable requires a Comment, It expresses not its purpose.

Bsp:

int d //Anzahl vergangener Tage
besser ist:
int daysSinceCreation;

Pronounceable name use

No constructs with unclear abbreviations as: int daSiCre instead of daysSinceCreation.

Searchable name use

Modern IDEs make searching easy, but it's no, when you have to look for the letters e and a control variable is swamped by results.

Variable names with a letter must only be used as local variables in short methods.

more…

As ZigBee saves the energy for the operation of the devices

ZigBee networks are very energy efficient and durable. One can easily an end device without a power source for 5years as. attach to a wall and you work with your own internal mini battery continues.

The reason for programmatic perspective, the system interrupts the, which the hardware of a ZigBee devices when needed and off again. The components consume in sleep mode only 0,1% of energy in comparison to the normal operation.

more…