David Kastrup wrote:I like to phrase that a slightly different way: anyone can make something complicated, but it takes genius to make something simple. A very big goal for D is to make what should be simple code, simple. It turns out that what's simple for a computer is complex for a human. So to design a language that is simple for programmers is (unfortunately) a rather complex problem. Or perhaps I'm just not smart enough <g>. A canonical example is that of a loop. Consider a simple C loop over an array: void foo(int array[10]) { for (int i = 0; i < 10; i++) { int value = array[i]; ... do something ... } } It's simple, but it has a lot of problems: 1) i should be size_t, not int 2) array is not checked for overflow 3) 10 may not be the actual array dimension 4) may be more efficient to step through the array with pointers, rather than indices 5) type of array may change, but the type of value may not get updated 6) crashes if array is NULL 7) only works with arrays and pointers Since this thread is talking about C++, let's look at the C++ version: void foo(std::vector<int> array) { for (std::vector<int>::const_iterator i = array.begin(); i != array.end(); i++) { int value = *i; ... do something ... } } It has fewer latent bugs, but still: 1) type of array may change, but the type of value may not get updated 2) too darned much typing 3) it's more complicated, not simpler Frankly, I don't want to write loops that way. I want to write them like this: void foo(int[] array) { foreach (value; array) { ... do something ... } } As a programmer, I'm specifying exactly what I want to happen without much extra puffery. It's less typing, simpler, and more resistant to bugs. 1) correct loop index type is selected based on the type of array 2) arrays carry with them their dimension, so foreach is guaranteed to step through the loop the correct number of times 3) implementation decides if pointers will do a better job than indices, based on the compilation target 4) type of value is inferred automatically from the type of array, so no worries if the type changes 5) Null arrays have 0 length, so no crashing 6) works with any collection type [This example is extracted from a presentation I've made.] ------ Walter Bright http://www.digitalmars.com C, C++, D programming language compilers http://www.astoriaseminar.com Extraordinary C++ - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
| Herbert Poetzl | Re: [ckrm-tech] [PATCH 0/2] resource control file system - aka containers on top o... |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
| Mark Lord | Re: 2.6.25-rc7: Ugh. |
| Cornelia Huck | Re: 2.6.25-rc3-mm1 |
git: | |
| Lea Wiemann | [PATCH 0/3] Git::Repo API and gitweb caching |
| Randal L. Schwartz | Re: pull into dirty working tree |
| Johannes Schindelin | Re: [PATCH] better git-submodule status output |
| Johannes Schindelin | Re: [PATCH] Add a new lstat and fstat implementation based on Win32 API |
| Richard Stallman | Re: Real men don't attack straw men |
| GVG GVG | ssh_exchange_identification: Connection closed by remote host |
| thacrazze | Multiboot Windows XP + OpenBSD doesnt work |
| askthelist | Packets Per Second Limit? |
| Jim Winstead Jr. | Re: Root Disk/Book Disk Compatibility |
| Stephen Pierce | SLS |
| drew | Re: Linux-0.12 |
| Sunando Sen | Re: [Q] "Cannot execute /bin/*sh: Permission denied" prevents login |
