Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Languages Misc > Re: Declaration...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 50 Topic 1065 of 1217
Post > Topic >>

Re: Declaration design preference: type or name first

by Logan Shaw <lshaw-usenet@[EMAIL PROTECTED] > Oct 31, 2007 at 11:45 PM

Mike Sieweke wrote:
> In article <4727ee13$0$20603$4c368faf@[EMAIL PROTECTED]
>,
>  Logan Shaw <lshaw-usenet@[EMAIL PROTECTED]
> wrote:
>> And for that, I draw a parallel to human language.  Human languages
>> are almost evenly split among those which have an adjective-noun
>> order and those which have a noun-adjective order.  English, which
>> is my native language, has an adjective-noun order ("black cat");
>> Spanish has a noun-adjective order ("gato negro")[1].

> I think you've chosen the wrong language model.  Variable definitions
> are more like a dictionary than like a sentence.  Have you ever seen
> a dictionary where the definition came before the defined word?

I've seen a few weird variations on dictionaries, but I guess one where
the entire definition comes before the word is not among them.

By the same token, I think pretty much all dictionaries I've seen have
been arranged in alphabetical order.  If we wanted to model variable
declarations on dictionaries, we'd have the variables declared in
alphabetical order.  But I wouldn't want to do that; I like putting
related things together.

> "Name first" has a subtle advantage:  Programmers tend to line 
> definitions up in columns, and name-first causes the names to
> be lined up.  The name-first form makes it easier to find a
> variable name in a list, just like in a dictionary.
> 
> x : integer
> y : float
> t : type = integer
> c : constant := 4
> a, b : character

> "Type first" tends to line up the types, leaving the names at
> random columns, as in C:
> 
> int x
> float y
> typedef int t
> const int c = 4
> char a, b

Sure, they do line up better, and that helps, but you've stacked
the deck a little bit by using " " to separate the items in the
second example and the more-visually-distinctive " : " to separate
them in the first.

The fairer comparison would be this:

     integer : x
     float : y
     type : t = integer
     constant : c := 4
     character : a, b

It's not as easy for the eye to search for variable names as it is
when they all start in the same column, but it's easier with the
trail of colons to guide the eye along.

Incidentally, variable name is not *always* what I want to visually
scan for.  When I'm looking at some code for the first time, I've
often seen what its interface is like and I know what some arguments
to its functions are.  So I'm often coming from a point of view where
I'm familiar with the types that the module deals with much more than I
am with what variable names it uses internally, and at least initially
I'm thinking in terms of the types and trying to find variable names
for them.  (Of course in your example it's very easy to find the types
as well, but that's because you chose variables names that are all
one length.)

Anyway, I guess this all goes to show that once you start making
analogies and deciding things are natural because of them, somebody
will make a different analogy that you thought of and think whatever
decision you made is quite unnatural since it doesn't harmonize with
the first analogy *they* thought of.

   - Logan
 




 50 Posts in Topic:
Declaration design preference: type or name first
James Harris <james.ha  2007-10-30 06:25:49 
Re: Declaration design preference: type or name first
Christopher Barber <cb  2007-10-30 12:04:41 
Re: Declaration design preference: type or name first
Robbert Haarman <comp.  2007-10-31 11:18:39 
Re: Declaration design preference: type or name first
Marco van de Voort <ma  2007-10-31 14:53:22 
Re: Declaration design preference: type or name first
"cr88192" <c  2007-10-31 08:29:19 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-10-30 16:01:31 
Re: Declaration design preference: type or name first
"cr88192" <c  2007-10-31 11:22:00 
Re: Declaration design preference: type or name first
Logan Shaw <lshaw-usen  2007-10-30 21:54:26 
Re: Declaration design preference: type or name first
Mike Sieweke <msieweke  2007-10-31 22:47:45 
Re: Declaration design preference: type or name first
CBFalconer <cbfalconer  2007-10-31 22:38:47 
Re: Declaration design preference: type or name first
Marco van de Voort <ma  2007-11-01 08:38:05 
Re: Declaration design preference: type or name first
Logan Shaw <lshaw-usen  2007-10-31 23:45:26 
Re: Declaration design preference: type or name first
Mike Sieweke <msieweke  2007-11-01 21:26:24 
Re: Declaration design preference: type or name first
Richard Heathfield <rj  2007-11-01 05:31:44 
Re: Declaration design preference: type or name first
Marco van de Voort <ma  2007-11-01 08:39:55 
Re: Declaration design preference: type or name first
Richard Heathfield <rj  2007-11-01 08:59:25 
Re: Declaration design preference: type or name first
Marco van de Voort <ma  2007-11-01 08:38:56 
Re: Declaration design preference: type or name first
cri@[EMAIL PROTECTED] (R  2007-11-01 14:40:44 
Re: Declaration design preference: type or name first
ram@[EMAIL PROTECTED] (S  2007-11-01 14:50:16 
Re: Declaration design preference: type or name first
cri@[EMAIL PROTECTED] (R  2007-11-01 15:52:23 
Re: Declaration design preference: type or name first
Logan Shaw <lshaw-usen  2007-11-01 20:09:07 
Re: Declaration design preference: type or name first
cri@[EMAIL PROTECTED] (R  2007-11-02 03:52:34 
Re: Declaration design preference: type or name first
Logan Shaw <lshaw-usen  2007-11-02 00:57:24 
Re: Declaration design preference: type or name first
cri@[EMAIL PROTECTED] (R  2007-11-03 15:53:21 
Re: Declaration design preference: type or name first
"cr88192" <c  2007-11-03 22:27:59 
Re: Declaration design preference: type or name first
thomas.mertes@[EMAIL PROT  2007-10-30 23:48:38 
Re: Declaration design preference: type or name first
thomas.mertes@[EMAIL PROT  2007-10-31 00:12:07 
Re: Declaration design preference: type or name first
torbenm@[EMAIL PROTECTED]  2007-10-31 09:27:23 
Re: Declaration design preference: type or name first
thomas.mertes@[EMAIL PROT  2007-10-31 01:38:54 
Re: Declaration design preference: type or name first
Marco van de Voort <ma  2007-10-31 14:45:15 
Re: Declaration design preference: type or name first
Ed Prochak <edprochak@  2007-10-31 17:28:45 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-01 13:56:47 
Re: Declaration design preference: type or name first
"cr88192" <c  2007-11-02 16:01:12 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-02 01:08:01 
Re: Declaration design preference: type or name first
CBFalconer <cbfalconer  2007-11-02 07:51:18 
Re: Declaration design preference: type or name first
Tzy-Jye Daniel Lin <dt  2007-11-03 03:28:22 
Re: Declaration design preference: type or name first
"cr88192" <c  2007-11-03 21:54:27 
Re: Declaration design preference: type or name first
torbenm@[EMAIL PROTECTED]  2007-11-05 09:56:58 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-05 10:33:42 
Re: Declaration design preference: type or name first
torbenm@[EMAIL PROTECTED]  2007-11-06 09:39:46 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-11 10:10:54 
Re: Declaration design preference: type or name first
Robbert Haarman <comp.  2007-11-12 12:17:10 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-12 15:18:18 
Re: Declaration design preference: type or name first
Robbert Haarman <comp.  2007-11-13 09:43:11 
Re: Declaration design preference: type or name first
torbenm@[EMAIL PROTECTED]  2007-11-13 10:14:08 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-13 15:47:48 
Re: Declaration design preference: type or name first
Robbert Haarman <comp.  2007-11-14 03:36:24 
Re: Declaration design preference: type or name first
anw@[EMAIL PROTECTED] (D  2007-11-14 13:11:46 
Re: Declaration design preference: type or name first
torbenm@[EMAIL PROTECTED]  2007-11-14 11:36:07 
Re: Declaration design preference: type or name first
James Harris <james.ha  2007-11-13 16:04:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 23:41:33 CDT 2008.