"bearophile" <[email protected]> wrote in message news:[email protected]... > Ali Ãehreli: >> $ has always bugged me anyway, so how about no character at all: > > The $ is not elegant, but it's a good solution to a design problem, how to > represent items from the bottom of the array. In Python you write: > a[-5] > In D you write: > a[$-5] > > This small one-char difference has an important effect for a system > language: the presence of $ allows you to avoid a conditional each time > you want to access an array item :-) > So I think it as one of the smartest details of D design :-) >
Once upon a time, there was a book called "Writing Solid Code". It seemed that anyone who was an established, respectable programmer swore by it and proclaimed it should be required reading by all programmers. These days, I sometimes feel like I'm the only one who's ever heard of it (let alone read it). So much of the book has made such an impact on me as a programmer, that from the very first time I ever heard of a language (probably Python) using "someArray[-5]" to denote an index from the end, I swear, the very first thought that popped into my head was "Candy-Machine Interface". I instantly disliked it, and still consider it a misguided design. For anyone who doesn't see the the problem with Python's negative indicies (or anyone who wants to delve into one of the forerunners to great books like "Code Craft" or "The Pragmatic Programmer"), I *highly* recommend tracking down a copy of "Writing Solid Code" and reading "The One-Function Memory Manager" and "Wishy-Washy Inputs", both in the "Candy-Machine Interfaces" chapter. (Although, the book did have such an impact on the programming world at the time, that many of the cautions in it sound like no-brainers today, like not using return values to indicate error codes. But even for those, it goes into much more detail on the "why" than what you usually hear.)
