Prev: Binary heap "tie breaking" question
Next: CFP: SAS'2010 - 17th International Static Analysis Symposium, Perpignan, France
From: cbcurl on 17 Feb 2010 10:46 On Feb 16, 10:21 pm, mike <m....(a)irl.cri.replacethiswithnz> wrote: > In article <5225f641-a135-4c5f-a091-11eeb2731264 > @z11g2000yqz.googlegroups.com>, cbc...(a)gmail.com says...> On Feb 16, 2:33 pm, "bartc" <ba...(a)freeuk.com> wrote: > > > > What if you had an array of those? > > > I can't imagine why one would have such a thing, but the plural would > > be numbers-of-persons, > > which I suppose one could abbreviate to ns-persons, although I > > wouldn't. I would probably just > > call it n-persons-array. See there is no hard and fast rule other than > > to make the code readable > > by humans. > > And then the number of entries in _that_ array would be n-n-persons- > array or n-ns-persons or ... First explain why you would even have such an array. I often find that data structures that are hard to name indicate the code needs to be refactored.
From: mike on 17 Feb 2010 17:13 In article <0c7fc58c-cc7d-4292-880f-aefab63e7622 @t21g2000vbo.googlegroups.com>, cbcurl(a)gmail.com says... > On Feb 16, 10:21 pm, mike <m....(a)irl.cri.replacethiswithnz> wrote: > > In article <5225f641-a135-4c5f-a091-11eeb2731264 > > @z11g2000yqz.googlegroups.com>, cbc...(a)gmail.com says...> On Feb 16, 2:33 pm, "bartc" <ba...(a)freeuk.com> wrote: > > > > > > What if you had an array of those? > > > > > I can't imagine why one would have such a thing, but the plural would > > > be numbers-of-persons, > > > which I suppose one could abbreviate to ns-persons, although I > > > wouldn't. I would probably just > > > call it n-persons-array. See there is no hard and fast rule other than > > > to make the code readable > > > by humans. > > > > And then the number of entries in _that_ array would be n-n-persons- > > array or n-ns-persons or ... > > First explain why you would even have such an array. I often find that > data structures that are hard to name indicate the code needs to be > refactored. > That is my point - an array is a useful data structure, but is not generally a good or useful in the high-level description of the data. Knowing, for example, that variable 'x' is an array of arrays of arrays is (with a few exceptions) not particularly useful and shouldn't be part of the name of the variable. If you have a Soldier object, then you could group them in Squad objects, which are themselves grouped into Platoons, Companies,...etc. Grouping them into Soldier_Array and Soldier_Array_Array etc would be unhelpful. So if you have a need for a list of pointers to arrays of strings, isn't it better to give it a name like Catalogue to both describe and justify the grouping of the data, rather than some horror like str_ary_ptr_lst? Cheers, Mike
From: bartc on 17 Feb 2010 18:13 mike wrote: > In article <0c7fc58c-cc7d-4292-880f-aefab63e7622 > @t21g2000vbo.googlegroups.com>, cbcurl(a)gmail.com says... >> On Feb 16, 10:21 pm, mike <m....(a)irl.cri.replacethiswithnz> wrote: >>> In article <5225f641-a135-4c5f-a091-11eeb2731264 >>> @z11g2000yqz.googlegroups.com>, cbc...(a)gmail.com says...> On Feb >>> 16, 2:33 pm, "bartc" <ba...(a)freeuk.com> wrote: >>> >>>>> What if you had an array of those? >>> >>>> I can't imagine why one would have such a thing, but the plural >>>> would be numbers-of-persons, >>>> which I suppose one could abbreviate to ns-persons, although I >>>> wouldn't. I would probably just >>>> call it n-persons-array. See there is no hard and fast rule other >>>> than to make the code readable >>>> by humans. >>> >>> And then the number of entries in _that_ array would be n-n-persons- >>> array or n-ns-persons or ... >> >> First explain why you would even have such an array. I often find >> that data structures that are hard to name indicate the code needs >> to be refactored. >> > That is my point - an array is a useful data structure, but is not > generally a good or useful in the high-level description of the data. > Knowing, for example, that variable 'x' is an array of arrays of > arrays > is (with a few exceptions) not particularly useful and shouldn't be > part > of the name of the variable. Yes, I don't think I've ever used 'array' or any of it's abbreviations as part of a variable name. But I have used 'list' or 'table' or whatever, or a plural, or sometimes a name that implies a list or collection or table. In short, I've used everything except 'array' (although I do make use of that for type names). -- Bartc
From: Curtis Dyer on 21 Feb 2010 00:16 bartc wrote: > mike wrote: >> In article <0c7fc58c-cc7d-4292-880f-aefab63e7622 >> @t21g2000vbo.googlegroups.com>, cbcurl(a)gmail.com says... >>> On Feb 16, 10:21 pm, mike <m....(a)irl.cri.replacethiswithnz> >>> wrote: >>>> In article <5225f641-a135-4c5f-a091-11eeb2731264 >>>> @z11g2000yqz.googlegroups.com>, cbc...(a)gmail.com says...> On >>>> Feb 16, 2:33 pm, "bartc" <ba...(a)freeuk.com> wrote: <snip methods for indicating arrays in identifiers> >>>> And then the number of entries in _that_ array would be >>>> n-n-persons- array or n-ns-persons or ... >>> >>> First explain why you would even have such an array. I often >>> find that data structures that are hard to name indicate the >>> code needs to be refactored. >>> >> That is my point - an array is a useful data structure, but is >> not generally a good or useful in the high-level description of >> the data. Knowing, for example, that variable 'x' is an array of >> arrays of arrays is (with a few exceptions) not particularly >> useful and shouldn't be part of the name of the variable. > > Yes, I don't think I've ever used 'array' or any of it's > abbreviations as part of a variable name. IIRC, the only time I've used "array" or an abbreviation of "array" was when writing general array manipulation functions in PHP. > But I have used 'list' or 'table' or whatever, or a plural, or > sometimes a name that implies a list or collection or table. In > short, I've used everything except 'array' (although I do make use > of that for type names). I think you make a good point here. When it comes to discussing identifiers in general, it can be tough, because choosing a good identifier greatly depends on the context in which a variable is declared. So "list" or "table" will certainly be sufficient in the proper contexts. I find Rob Pike's "Notes on Programming in C"* an insightful guide concerning programming style in general. * <http://www.lysator.liu.se/c/pikestyle.html> -- Curtis Dyer "Don't worry about efficiency until you've attained correctness." -- Eric Sosman, CLC
First
|
Prev
|
Pages: 1 2 3 4 5 6 Prev: Binary heap "tie breaking" question Next: CFP: SAS'2010 - 17th International Static Analysis Symposium, Perpignan, France |