Re: Cleaning code
  Home FAQ Contact Sign in
comp.lang.misc only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.misc Profile…
 Up
Re: Cleaning code         


Author: Richard Harter
Date: Jul 18, 2008 12:38

On Thu, 17 Jul 2008 11:57:34 -0400, "S James S Stapleton"
osu.edu> wrote:
>There's a programming construct I've thought of, and I've been searching on
>for it for a while, and haven't found any ideas on why it has/hasn't been
>implemented in any language.
>
>It's fairly obvious...
Show full article (4.43Kb)
30 Comments
Re: Cleaning code         


Author: S James S Stapleton
Date: Jul 18, 2008 12:46

> What might be interesting would be the capability of manipulating
> order relationship statements in much the same that one can
> manipulate boolean relationships. There is probably a whole body
> of theory out there that I don't know anything about. As an
> example, consider triplets of the form (x,y,v) where v is the
> order relationship between x and y. Then if we have two triplets
> (x,y,u) and (y,z,v) and we know that u=v then we also know that
> (x,z,v).

You got my idea fairly well I think. Your psudocode was definitely better
than mine.

I've been considering trying to add this idea to python. I like your concept
of an ordering type.

Thanks for the input,
-Jim Stapleton
no comments
Re: Cleaning code         


Author: Bart
Date: Jul 18, 2008 16:27

On Jul 18, 8:38 pm, c...@tiac.net (Richard Harter) wrote:
> On Thu, 17 Jul 2008 11:57:34 -0400, "S James S Stapleton"
> osu.edu> wrote:
>>There's a programming construct I've thought of, and I've been searching on
>>for it for a while, and haven't found any ideas on why it has/hasn't been
>>implemented in any language.
> Then there is the question of what the comparison yields.  In C
> strcmp yields -1, 0, and 1. However this is a hack.  Decent
> languages have a native boolean type with values true and false;
> one could consider having a native three valued type with values
> lt, eq, and gt.

You're forgetting le and ge, which would be easier to deal with using
-1,0,1.

There's also ne, but I'm not sure how that would fit in. Perhaps a
relative compare should return the 3-element set [lt, eq, gt]. Then le
is [lt,eq], ge is [eq,gt]. 'ne' is best expressed as not [eq].

--
Bartc
no comments
Re: Cleaning code         


Author: Ben Bacarisse
Date: Jul 18, 2008 16:45

cri@tiac.net (Richard Harter) writes:
> This is sort of interesting, to me anyway, but I perceive it as a
> language design issue. Accordingly, I've added comp.lang.misc to
> the newsgroups.
> ... Decent
> languages have a native boolean type with values true and false;
> one could consider having a native three valued type with values
> lt, eq, and gt.

Or LT, GT and EQ in Haskell. I don't see why the type needs to be
native unless, by that, you mean that any built-in types must have an
operator that produces the correct values.

The Haskell's type classes (in particular Eq and Ord) are, in my
opinion, an object lesson in how to design equality and ordering in a
programming language. If you are interested in this area you must at
least see how it is done there.

--
Ben.
no comments
Re: Cleaning code         


Author: Reinder Verlinde
Date: Jul 18, 2008 17:13

In article
<5e9bb46e-dfdb-4872-bc95-105bb6cb1730@i76g2000hsf.googlegroups.com>,
Bart freeuk.com> wrote:
> On Jul 18, 8:38
no comments
Re: Cleaning code         


Author: Rod Pemberton
Date: Jul 19, 2008 01:14

"Richard Harter" tiac.net> wrote in message
news:4880bd90.86727125@news.sbtc.net...
> On Thu, 17 Jul 2008 11:57:34 -0400, "S James S Stapleton"
> osu.edu> wrote:
>
>>There's a programming construct I've thought of, and I've been searching
on
>>for it for a while, and haven't found any ideas on why it has/hasn't been
>>implemented in any language.
>>
>>It's fairly obvious, so I'm sure there's a reason, could someone point me
in
>>the right direction?
>>
>>
>>The construct: NIF
>>Rationale: Numerical IF, used for comparisons. Many functions, such as
>>strcmp in C, as an example, have negative values for less than, 0 for
>>greater than, and 1 for equal. Three options, however, you can either use
>>two options with an if (if/else), or have many options for a switch - all ...
Show full article (2.97Kb)
no comments
Re: Cleaning code         


Author: Richard Harter
Date: Jul 19, 2008 07:40

On Fri, 18 Jul 2008 16:27:39 -0700 (PDT), Bart freeuk.com>
wrote:
>On Jul 18, 8:38=A0pm, c...@tiac.net (Richard Harter) wrote:
>> On Thu, 17 Jul 2008 11:57:34 -0400, "S James S Stapleton"
>> osu.edu> wrote:
>>>There's a programming construct I've thought...
Show full article (1.28Kb)
no comments
Re: Cleaning code         


Author: Richard Harter
Date: Jul 19, 2008 07:44

On Sat, 19 Jul 2008 00:45:23 +0100, Ben Bacarisse
wrote:
>cri@tiac.net (Richard Harter) writes:
>
>> This is sort of interesting, to me anyway, but I perceive it as a
>> language design issue. Accordingly, I've added comp.lang.misc to
>> the newsgroups.
>
>> ... Decent
>> languages have a native boolean type with values true and false;
>> one could consider having a native three valued type with values
>> lt, eq, and gt.
>
>Or LT, GT and EQ in Haskell. I don't see why the type needs to be
>native unless, by that, you mean that any built-in types must have an
>operator that produces the correct values.

I like Erlang's approach to case - identifiers are lower case,
atoms are upper case. It's ever so much cleaner.
Show full article (1.24Kb)
no comments
Re: Cleaning code         


Author: lawrence.jones
Date: Jul 19, 2008 13:14

Richard Harter tiac.net> wrote:
>
> No, the compare should return one of the three. To get le, ne,
> or ge, do a boolean negation, e.g., in C, le is
> !(compare(x,y)==gt).

Or just use the not equal operator: compare(x,y)!=gt.
--
Larry Jones

The hardest part for us avant-garde post-modern artists is
deciding whether or not to embrace commercialism. -- Calvin
no comments
Re: Cleaning code         


Author: S James S Stapleton
Date: Jul 21, 2008 05:55

> No offense - I'm curious, but I don't see what value this offers. With a
> function like strcmp(), you wan't either a true/false result or you want a
> specific one out of three result. I.e., are they equal or not? Or, how
> are
> they different?

Exactly, how are they different is the point here. Is the first less than,
equal to or greater than the second?

In each one may have a different requirement.

The use would be in sorting and binary searches mostly. It could clean up
the code.
> It is "nifty" that they combined two methods of comparison
> into a single function. So, I don't understand why you'd need two or
> three
> of three results. But, if you did, you just save the result to a
> temporary
> variable or "flag" and use another if() or 'else if()'... Also, compilers
> optimize switch() very well.
Show full article (2.64Kb)
no comments
1 2 3 4