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
| Andrea Arcangeli | [PATCH 00 of 12] mmu notifier #v13 |
| David Newall | Re: What still uses the block layer? |
| Greg Kroah-Hartman | [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO |
| Konrad Rzeszutek | [PATCH] Add iSCSI iBFT support (v0.4.5) |
git: | |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| David Miller | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Stefan Richter | Re: [GIT]: Networking |
| Antonio Almeida | HTB accuracy for high speed |
