Whitespace

Most modern programming languages do not consider white space characters (spaces, tabs and newlines) syntax, ignoring them, as if they weren’t there. We consider this to be a gross injustice to these perfectly friendly members of the character set. Should they be ignored, just because they are invisible? Whitespace is a language that seeks to redress the balance. Any non whitespace characters are ignored; only spaces, tabs and newlines are considered syntax.

Whitespace must be learned.

2 thoughts on “Whitespace”

  1. Freedom to use whitespace as we see fit should be in the programmers constitution !

  2. I had the same problem derRaab! Replace \t by fixed spaecs is not really correct, tab char represent variables space char. I wrote a quickly solution making this two changes in wp-syntax/wp-syntax.php:Change 1:if ($this->header_type != GESHI_HEADER_PRE && $this->header_type != GESHI_HEADER_PRE_VALID) {$this->indent($parsed_code);} else{$this->indentPRE($parsed_code);}Change 2, insert a new funtion for my pre-blocks:function indentPRE(&$result) {/// Replace tabs with the correct number of spaecsif (false !== strpos($result, “\t”)) {$lines = explode(“\n”, $result);$result = null;//Save memory while we process the lines individually$tab_width = $this->get_real_tab_width();$tab_string = ‘ ‘ . str_repeat(‘ ‘, $tab_width);for ($key = 0, $n = count($lines); $key ‘ ‘,// 3 => ‘ ‘ etc etc// to use instead of building a string every time$tab_end_width = $tab_width – ($pos % $tab_width); //Moved out of the look as it doesn’t change within the loopif (($pos & 1) || 1 == $tab_end_width) {$str .= substr($tab_string, 6, $tab_end_width);} else {$str .= substr($tab_string, 0, $tab_end_width+5);}$lines[$key] .= $str;$pos += $tab_end_width;if (false === strpos($line, “\t”, $i + 1)) {$lines[$key] .= substr($line, $i + 1);break;}} else if (0 == $pos && ‘ ‘ == $char) {$lines[$key] .= ‘ ‘;++$pos;} else {$lines[$key] .= $char;++$pos;}}}$result = implode(“\n”, $lines);unset($lines);//We don’t need the lines separated beyond this — free them!}}This last function is a copy-paste-modify of ident().If I didn’t make a mistake this corrected tab’s size (in my case 8 to 4).

Leave a Reply

Your email address will not be published. Required fields are marked *