[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Tabs v.s. spaces



H. S. Teoh wrote:
Not for any non-trivial task, although I did try to learn it some time
ago. Recently, I had the chance to take another look at it; however, I
found Ruby, which seemed to have the best of both Perl and Python plus
true object-orientation. So when I move on from Perl (which I love, but
which admittedly has its flaws too), it will be to Ruby, not Python.

Perl has good points? *shudder* I looked at Ruby and saw that it was taking many of the bad points of Perl.

	PARSE: {
	  m/\G (void|int|float) /gcx && do { $type = $1 };
	  m@\G /\*([^*]+|\*[^/])*\*\/@gcx && next PARSE;
	  m/\G \s+ /gcx && next PARSE;
	  m/\G \{ /gcx && do {
	    my @statements =  parse_block;
	    push @block, @statements;
	  };
	}

    Possible.

	try {
	  obj_handle handle = get_handle();
	  handle.write(data);
	  if (handle.error()) throw exception(obj_handle::write_error);

	  handle.verify(data);
	  if (handle.error()) throw exception(obj_handle::verify_error);

	  handle.commit();
	  if (handle.error()) {
            commit_errors++;
	    if (retry_needed) {
              retry_request();
	    }
	  }
	}

    Possible.


More Perl examples:
	open FILE, $file1 or die "Unable to open $file1: $!\n";
	while (<FILE>) {
	  ...
	}
	close FILE or die "Error while reading $file1: $! ($?)\n";
	open FILE, $file2 or do {
	  ... # do something else
	};
	...

    Possible.


Next example (C):
	for (i=0; i<n; i++) {
	  struct iterator *it;
	  for (it=get_iter(data.values.list);
	       more_elements(it) && value_of(it)!=search_value;
	       step(it));
	  if (value_of(it)==search_value) return 1;
	}

    Possible.

Output example (C/C++):
	if (debug==1)
		printf(gettext("Debug dump:\n"
		               "Current registers: %s\n"
		               "Watch values: %s\n"),
		       get_register_dump(),
		       get_watch_values());

    Possible.

Finally, constructors example (C++):
	classA::classA(int x, int y) : xcoor(x), ycoor(y) {}
	classB::classB(void (*)(int x, int y),
	               void classA::*callback(int i)) :
		xcoor(x), ycoor(y), cb(callback) {
	  if (callback==NULL) throw exception();
	}

    Possible.

Note how the flexibility to indent makes it possible to write simple
constructors on one line (classA), and layout complex constructors such as
in classB such that separate elements are clearly separated.

So exactly where's your problem with the white space again? If you really wanted to do each of those you could easily enough. Oddly enough in each case you'll mostly be removing braces. I hope this concludes the topic for those who haven't touched Python badmouthing the whitespace issue since, thus far, I've yet to see a single example which isn't possible in pretty much the exact same visual style.

--
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
       PGP Key: 8B6E99C5       | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------

Attachment: pgpSfhqZuwPBZ.pgp
Description: PGP signature


Reply to: