Main Page | Report this Page
Computers Forum Index  »  Computer - Object  »  Looking for real world examples to explain the...
Page 2 of 2    Goto page Previous  1, 2

Looking for real world examples to explain the...

Author Message
Daniel T....
Posted: Sat May 23, 2009 4:23 pm
Guest
"cr88192" <cr88192 at (no spam) hotmail.com> wrote:
Quote:
"Daniel T." <daniel_t at (no spam) earthlink.net> wrote:
On May 21, 1:43 am, "cr88192" <cr88... at (no spam) hotmail.com> wrote:
"Daniel T." <danie... at (no spam) earthlink.net> wrote in message
On May 20, 12:40 pm, "cr88192" <cr88... at (no spam) hotmail.com> wrote:

typically, I don't use contexts for functions which are
essentially stateless (and will always be stateless). IMO,
it just seems a little silly to put these as static methods
in some particular class. similarly for types/objects which
are conceptually atomic and pass-by-value. ...

yes, such things exist...

You mean a procedure that doesn’t return information nor
change any values in memory?

well, it can return stuff...

but, yes, all input is provided in arguments, and any return
value depends purely on the input...

this is typical of many mathematical functions, ...
traditionally, these would be things like sin, cos, tan, ...

but could include things like sinc, integrators, interpolators,
... also typical is to implement custom math support, for
example, vector and quaternion support, ...

however, the typical "OO" mindset tends to ignore the existence
of things like this... (like, math is some kind of novelty no
"real" programmers use...).

but, yes, in these cases we don't need a context...

Hold on a second, obviously you do need a context because you
are passing in parameter(s)... they are your context.

Functions which require only one parameter fit nicely in the OO
model (e.g., sin, cos, and tan,) but I agree that there are many
functions which need more than one object[1] and there is no
reason to give any single object primacy.

[1]I'm using the definition of 'object' as it used in the C
standard.

what I mean by context here is a context-struct...

I'm confused... Context is context. The value returned by the function
is a (derived) property of the context isn't it?
 
cr88192...
Posted: Sat May 23, 2009 6:13 pm
Guest
"Daniel T." <daniel_t at (no spam) earthlink.net> wrote in message
news:daniel_t-CC46AB.08232723052009 at (no spam) earthlink.vsrv-sjc.supernews.net...
Quote:
"cr88192" <cr88192 at (no spam) hotmail.com> wrote:
"Daniel T." <daniel_t at (no spam) earthlink.net> wrote:
On May 21, 1:43 am, "cr88192" <cr88... at (no spam) hotmail.com> wrote:
"Daniel T." <danie... at (no spam) earthlink.net> wrote in message
On May 20, 12:40 pm, "cr88192" <cr88... at (no spam) hotmail.com> wrote:

typically, I don't use contexts for functions which are
essentially stateless (and will always be stateless). IMO,
it just seems a little silly to put these as static methods
in some particular class. similarly for types/objects which
are conceptually atomic and pass-by-value. ...

yes, such things exist...

You mean a procedure that doesn't return information nor
change any values in memory?

well, it can return stuff...

but, yes, all input is provided in arguments, and any return
value depends purely on the input...

this is typical of many mathematical functions, ...
traditionally, these would be things like sin, cos, tan, ...

but could include things like sinc, integrators, interpolators,
... also typical is to implement custom math support, for
example, vector and quaternion support, ...

however, the typical "OO" mindset tends to ignore the existence
of things like this... (like, math is some kind of novelty no
"real" programmers use...).

but, yes, in these cases we don't need a context...

Hold on a second, obviously you do need a context because you
are passing in parameter(s)... they are your context.

Functions which require only one parameter fit nicely in the OO
model (e.g., sin, cos, and tan,) but I agree that there are many
functions which need more than one object[1] and there is no
reason to give any single object primacy.

[1]I'm using the definition of 'object' as it used in the C
standard.

what I mean by context here is a context-struct...

I'm confused... Context is context. The value returned by the function
is a (derived) property of the context isn't it?

I mean more like:
typedef struct FooContext_s FooContext;
struct FooContext_s {
int a;
float *b;
....
};

int FooFuncA(FooContext *ctx, float a, float b);
int FooFuncB(FooContext *ctx, int v);
int FooFuncC(FooContext *ctx, char *name);
....


in this case, the context serves a similar role to an object instance in an
OO language.
a context may also serve as a way to eliminate using globals in some cases
as well...


as I see it, arguments are not part of the general context of a function
(nor especially part of a context struct), but are more specific (they only
apply to the current invokation, and not to any side-state).

so, in my definitions, a function is "context independent" if the only
values it uses are those passed in as arguments (especially if it is such to
where "algebraic" properties/techniques can be used), and by extension no
external state is modified, which is often the case with math-related code.

so, for example, something like 'sinc' would be implemented as a
context-independent function, but a function like 'fread' could not be
(since 'FILE' is effectively stateful, as well as any external files for
which it may reference, ...).
 
Paul Sinnett...
Posted: Sun May 24, 2009 9:33 am
Guest
On May 23, 3:13 pm, "cr88192" <cr88... at (no spam) hotmail.com> wrote:
Quote:
as I see it, arguments are not part of the general context of a function
(nor especially part of a context struct), but are more specific (they only
apply to the current invokation, and not to any side-state).

so, in my definitions, a function is "context independent" if the only
values it uses are those passed in as arguments

In C/C++ on some platforms, arguments can be packed into structs
automatically by the compiler. This is because the calling conventions
on some processors only allow for a very limited number of registers
to be used.

So your definition would consider the same function context
independent on one platform and dependent on another. I don't think
that's what you want. Packing arguments into to structs is also widely
used to make the management of large blocks of related data easier. We
are much more likely to pass a matrix as a structure that as 16 floats
for example. But that doesn't make those functions any less pure.
 
Paul Sinnett...
Posted: Sun May 24, 2009 8:35 pm
Guest
On May 24, 4:15 pm, "cr88192" <cr88... at (no spam) hotmail.com> wrote:
Quote:
so, yes, matmult can remain context independent;
however, fread/fwrite/fseek, or for that matter, much of my compiler
machinery, would not be...

Right. So by context independent, you mean the same as pure functional?
 
cr88192...
Posted: Mon May 25, 2009 1:16 am
Guest
"Paul Sinnett" <paul.sinnett at (no spam) gmail.com> wrote in message
news:64a45819-a0df-4c23-a560-cf44b5b9eb71 at (no spam) q14g2000vbn.googlegroups.com...
On May 24, 4:15 pm, "cr88192" <cr88... at (no spam) hotmail.com> wrote:
Quote:
so, yes, matmult can remain context independent;
however, fread/fwrite/fseek, or for that matter, much of my compiler
machinery, would not be...

Right. So by context independent, you mean the same as pure functional?


more or less...

to be more specific, pure functional does not allow assignments, whereas my
definitions would allow assignments within the function in question, just
nothing to variables external to this function.

(FWIW, non-trivial pure FP code would not likely be possible, or at least
practical, in C...).
 
Daniel T....
Posted: Tue May 26, 2009 4:15 pm
Guest
"cr88192" <cr88192 at (no spam) hotmail.com> wrote:
Quote:
"Daniel T." <daniel_t at (no spam) earthlink.net> wrote:
"cr88192" <cr88192 at (no spam) hotmail.com> wrote:
"Daniel T." <daniel_t at (no spam) earthlink.net> wrote:
On May 21, 1:43 am, "cr88192" <cr88... at (no spam) hotmail.com> wrote:
"Daniel T." <danie... at (no spam) earthlink.net> wrote in message
On May 20, 12:40 pm, "cr88192" <cr88... at (no spam) hotmail.com> wrote:

typically, I don't use contexts for functions which are
essentially stateless (and will always be stateless).
IMO, it just seems a little silly to put these as static
methods in some particular class. similarly for
types/objects which are conceptually atomic and
pass-by-value. ...

yes, such things exist...

You mean a procedure that doesn't return information nor
change any values in memory?

well, it can return stuff...

but, yes, all input is provided in arguments, and any return
value depends purely on the input...

this is typical of many mathematical functions, ...
traditionally, these would be things like sin, cos, tan, ...

but could include things like sinc, integrators,
interpolators, ... also typical is to implement custom math
support, for example, vector and quaternion support, ...

however, the typical "OO" mindset tends to ignore the
existence of things like this... (like, math is some kind of
novelty no "real" programmers use...).

but, yes, in these cases we don't need a context...

Hold on a second, obviously you do need a context because you
are passing in parameter(s)... they are your context.

Functions which require only one parameter fit nicely in the
OO model (e.g., sin, cos, and tan,) but I agree that there are
many functions which need more than one object[1] and there is
no reason to give any single object primacy.

[1]I'm using the definition of 'object' as it used in the C
standard.

what I mean by context here is a context-struct...

I'm confused... Context is context. The value returned by the
function is a (derived) property of the context isn't it?

I mean more like:
typedef struct FooContext_s FooContext;
struct FooContext_s {
int a;
float *b;
...
};

int FooFuncA(FooContext *ctx, float a, float b);
int FooFuncB(FooContext *ctx, int v);
int FooFuncC(FooContext *ctx, char *name);
...


in this case, the context serves a similar role to an object
instance in an OO language. a context may also serve as a way to
eliminate using globals in some cases as well...

A similar role? It seems to me that the role is identical at least in
the case where there is only one parameter passed into the function. For
example sqrt. The square root of a number is a property of that number.

I agree with you when there are multiple parameters passed into the
function and no particular parameter has dominance.
 
 
Page 2 of 2    Goto page Previous  1, 2
All times are GMT
The time now is Wed Dec 09, 2009 12:51 am