Personal tools

Pairs of identifiers

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(moved from Hawiki)
 
m (Del)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Frequently functions appear in pairs like {{{hOpen}}} and {{{hClose}}}, {{{read}}} and {{{show}}} and so on.
+
Frequently functions appear in pairs like <hask>hOpen</hask> and <hask>hClose</hask>, <hask>read</hask> and <hask>show</hask> and so on.
 
Libraries are a lot easier to use if they use a consistent scheme of names for related functions.
 
Libraries are a lot easier to use if they use a consistent scheme of names for related functions.
 
It is even better if many libraries would share the same scheme.
 
It is even better if many libraries would share the same scheme.
Line 12: Line 12:
 
where for instance some duplicates are removed.
 
where for instance some duplicates are removed.
   
|| Create || Delete ||
+
{|
|| New || Dispose ||
+
| Create || Delete
|| Construct || Destruct ||
+
|-
|| Alloc || Free ||
+
| New || Dispose
|| Obtain || Release || Attempt ||
+
|-
|| Lock || UnLock ||
+
| Construct || Destruct
|| Procure || Vacate ||
+
|-
|| Forbid || Permit ||
+
| Alloc || Free
|| Disable || Enable ||
+
|-
|| Put || Get ||
+
| Obtain || Release || Attempt
|| Set || Get ||
+
|-
|| Write || Read ||
+
| Lock || UnLock
|| Poke || Peek ||
+
|-
|| Open || Close ||
+
| Procure || Vacate
|| Save || Load ||
+
|-
|| Load || UnLoad ||
+
| Forbid || Permit
|| Init || Exit ||
+
|-
|| Setup || Cleanup ||
+
| Disable || Enable
|| Show || Hide ||
+
|-
|| Insert || Remove ||
+
| Put || Get
|| Add || Rem ||
+
|-
|| Push || Pull ||
+
| Set || Get
|| Push || Pop ||
+
|-
|| Start || Stop || Size ||
+
| Write || Read
|| Begin || End || Length ||
+
|-
|| First || Last || Number ||
+
| Poke || Peek
|| Head || Tail ||
+
|-
|| Front || Back ||
+
| Open || Close
|| Top || Bottom ||
+
|-
|| Fmt || Lex ||
+
| Save || Load
|| Input || Output ||
+
|-
  +
| Load || UnLoad
  +
|-
  +
| Init || Exit
  +
|-
  +
| Setup || Cleanup
  +
|-
  +
| Show || Hide
  +
|-
  +
| Insert || Remove
  +
|-
  +
| Add || Rem
  +
|-
  +
| Push || Pull
  +
|-
  +
| Push || Pop
  +
|-
  +
| Start || Stop || Size
  +
|-
  +
| Begin || End || Length
  +
|-
  +
| First || Last || Number
  +
|-
  +
| Head || Tail
  +
|-
  +
| Front || Back
  +
|-
  +
| Top || Bottom
  +
|-
  +
| Fmt || Lex
  +
|-
  +
| Input || Output
  +
|-
  +
|}
   
  +
== Discussion ==
   
= Discussion =
+
=== read and show ===
   
I think the names {{{read}}} and {{{show}}} in the Prelude of Haskell98 aren't a good choice
+
I think the names <hask>read</hask> and <hask>show</hask> in the Prelude of Haskell98 aren't a good choice
 
because the functions can be considered as natural pair
 
because the functions can be considered as natural pair
 
but this isn't reflected by their names.
 
but this isn't reflected by their names.
Even more {{{read}}} and {{{show}}} sound like some I/O operations which they are not.
+
Even more <hask>read</hask> and <hask>show</hask> sound like some I/O operations which they are not.
The choice for the Modula-3 libraries ({{{Lex}}} and {{{Fmt}}}) seems to be more suitable. -- HenningThielemann
+
The choice for the Modula-3 libraries (<hask>Lex</hask> and <hask>Fmt</hask>) seems to be more suitable. -- HenningThielemann
   
I had a nice discussion the other day with someone about the right name for tree nodes and leaves. The constructors I'm using as a result are {{{Branch}}} and {{{Leaf}}}. Anyone feel differently? -- BartMassey
+
=== trees ===
  +
  +
I had a nice discussion the other day with someone about the right name for tree nodes and leaves. The constructors I'm using as a result are <hask>Branch</hask> and <hask>Leaf</hask>. Anyone feel differently? -- BartMassey
  +
  +
[[Category:Style]]
  +
  +
=== Del ===
  +
I think 'del' is more natural pair for 'add'. --Evgeny Tarasov

Latest revision as of 18:35, 22 April 2011

Frequently functions appear in pairs like
hOpen
and
hClose
,
read
and
show
and so on.

Libraries are a lot easier to use if they use a consistent scheme of names for related functions. It is even better if many libraries would share the same scheme. This can be useful both for designing function names and for easy guessing of the counterpart of some function.

Here is a collection of some pairs of identifiers I stumbled on in AmigaOS, MUI, Modula-3, Haskell libraries, and C++ STL. This could be a basis for further discussion.

It would be great if the discussion lead to a more streamlined collection where for instance some duplicates are removed.

Create Delete
New Dispose
Construct Destruct
Alloc Free
Obtain Release Attempt
Lock UnLock
Procure Vacate
Forbid Permit
Disable Enable
Put Get
Set Get
Write Read
Poke Peek
Open Close
Save Load
Load UnLoad
Init Exit
Setup Cleanup
Show Hide
Insert Remove
Add Rem
Push Pull
Push Pop
Start Stop Size
Begin End Length
First Last Number
Head Tail
Front Back
Top Bottom
Fmt Lex
Input Output

Contents

[edit] 1 Discussion

[edit] 1.1 read and show

I think the names
read
and
show
in the Prelude of Haskell98 aren't a good choice

because the functions can be considered as natural pair but this isn't reflected by their names.

Even more
read
and
show
sound like some I/O operations which they are not. The choice for the Modula-3 libraries (
Lex
and
Fmt
) seems to be more suitable. -- HenningThielemann

[edit] 1.2 trees

I had a nice discussion the other day with someone about the right name for tree nodes and leaves. The constructors I'm using as a result are
Branch
and
Leaf
. Anyone feel differently? -- BartMassey

[edit] 1.3 Del

I think 'del' is more natural pair for 'add'. --Evgeny Tarasov