Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #70717

Re: Two silly problems

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Two silly problems
Date 2019-12-28 07:37 +0100
Organization A noiseless patient Spider
Message-ID <qu6t75$tus$1@dont-email.me> (permalink)
References (1 earlier) <h6k3g7Fp6iaU1@mid.individual.net> <qu401n$vh4$1@dont-email.me> <4sqNF.162115$eP4.139233@fx23.dcg> <qu5kmb$qvh$1@dont-email.me> <gyxNF.89127$3sa.52754@fx02.dcg>

Show all headers | View raw


On 28.12.2019 01:42, Mr Flibble wrote:
> On 27/12/2019 19:05, Alf P. Steinbach wrote:
>> On 27.12.2019 17:38, Mr Flibble wrote:
>>>
>>> Egregious (std:: preferred).
>>
>> Why do you prefer to repeat a bit of text ad nauseam? It's more to 
>> write, more to read, recommended against by a number of generally 
>> accepted guidelines like DRY, and just plain freaking dumb. So, why?
> 
> Taking your really bad analogy of DRY to its logical conclusion you can 
> only use a vector once in your entire program so you don't fucking 
> repeat yourself.  Bad analogies are "just plain freaking dumb".

I can agree with the last sentence.

Regarding the rest, consider:


#include <array>

void leigh()
{
     const int board_size = 8;
     std::array<std::array<int, board_size>, board_size> board =
     {
         std::array<int, board_size>{}, std::array<int, board_size>{},
         std::array<int, board_size>{}, std::array<int, board_size>{},
         std::array<int, board_size>{}, std::array<int, board_size>{},
         std::array<int, board_size>{}, std::array<int, board_size>{}
     };
     (void) board; // Whatever
}

void alf()
{
     using std::array;

     const int width     = 8;
     const int height    = width;

     using Row       = array<int, width>;
     using Board     = array<Row, height>;

     Board board{};
     (void) board; // Whatever
}


Here the two functions manage to create a local variable called `board`, 
of the exact same type in the code as by your argumentation you would 
have written it, and in corresponding code by me.

In the assumed-like-Leigh code the `std::` qualification and the type 
builder `array` is repeated ad nauseam, because you argue that even when 
it's known that all textual instances are a given text it should better 
be spelled out; and the focus, what's communicated to a reader, is on 
the details of the data representation and not on what it models.

In the more DRY (Don't Repeat Yourself) Alf code the relevant namespace 
`std::` is mentioned only once; the type builder `array` is mentioned 
only in a `using` declaration and for the two types that it builds here, 
that is, three times; and the focus, what's communicated to a reader, is 
on what the structure models.

- Alf

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-26 16:47 +0100
  Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-26 16:51 +0100
  Re: Two silly problems Bo Persson <bo@bo-persson.se> - 2019-12-26 16:55 +0100
    Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-27 05:07 +0100
      Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-27 16:38 +0000
        Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-27 20:05 +0100
          Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 00:42 +0000
            Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-28 07:37 +0100
              Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 15:51 +0000
                Re: Two silly problems boltar@nowhere.org - 2019-12-28 16:30 +0000
                Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 17:15 +0000

csiph-web