novice questions

This is a discussion on novice questions within the Eiffel forums in Programming Languages category; Does Eiffel (SmartEiffel) have typedefs? I want to only have to change one line of code to go from single precision to double precision. Only using an alias to double/float accomplishes that. If Eiffel does not allow me to do something as trivial as that, doesn't it mean it fails one of its stated design goals (single-choice principle)? I've read that, for performance, it's possible to disable the assertions (or whatever you call them). Is there a finer-grained control over this? For example, can you easily disable all assertions that are not required for memory safety? (i.e. negative argument to ...

Go Back   Application Development Forum > Programming Languages > Eiffel

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 05-13-2008, 12:10 AM
jhc0033@gmail.com
Guest
 
Default novice questions

Does Eiffel (SmartEiffel) have typedefs? I want to only have to change
one line of code to go from single precision to double precision. Only
using an alias to double/float accomplishes that. If Eiffel does not
allow me to do something as trivial as that, doesn't it mean it fails
one of its stated design goals (single-choice principle)?

I've read that, for performance, it's possible to disable the
assertions (or whatever you call them). Is there a finer-grained
control over this? For example, can you easily disable all assertions
that are not required for memory safety? (i.e. negative argument to
sqrt is OK, but off-by-1 index is not)

What's the deal with "the Eiffel community destroyed itself"? What
does this refer to?

Eiffel is meant to target super-large software projects. As I
understand, it used to be reasonably popular. What is the most
complicated software written in Eiffel that is still being used?
Reply With Quote
  #2  
Old 05-13-2008, 03:04 AM
francesco.ferreri@gmail.com
Guest
 
Default Re: novice questions

Hi,
On May 13, 6:10 am, "jhc0...@gmail.com" <jhc0...@gmail.com> wrote:
> Does Eiffel (SmartEiffel) have typedefs? I want to only have to change
> one line of code to go from single precision to double precision. Only
> using an alias to double/float accomplishes that. If Eiffel does not
> allow me to do something as trivial as that, doesn't it mean it fails
> one of its stated design goals (single-choice principle)?


single-choice principle: "Whenever a software system must support a
set of alternatives, one and only one module in the system should know
their exhaustive list.".

This has to do mostly with the creation of objects at runtime: suppose
you have designed the general behaviour of your system in terms of
abstract operations on certain abstract data types (ADT); then you can
determine the actual behaviour of the system at runtime, by relying on
a hierarchy of classes implementing your ADTs. You should have only
one single place in your code where you know exactly what class of
objects you are instantiating at runtime, the rest of the system
should behave accordingly to the objects it is dealing with, without
having to know exactly its type.

As an example, suppose you have built an interactive software for
drawing geometric shapes: you will have a class SHAPE having a
deferred (abstract) method `draw' which is called whenever you need to
display a shape on the screen. Then you can build a hierarchy of
classes below SHAPE: CIRCLE, SQUARE, RECTANGLE, each one implementing
its version of the `draw' method. According to single-choice
principle, you should have only one place in your code where you know
which kind of objects you're creating at runtime: for example in
response to user input:

l_shape: SHAPE

if circle_requested_by_user
create {CIRCLE}l_shape.make
else if square_requested_by_user
create {SQUARE}l_shape.make
....

then the rest of your code will only deal with l_shape.draw, without
needing to know what class l_shape actually is.

As you can see, this has nothing to do with typedefs, which are tricks
you can use at compile time, not at runtime. If you ever happen to
need this in Eiffel, then you probably missed something in the design
of your system.

Regards,
Francesco
Reply With Quote
  #3  
Old 05-13-2008, 04:20 AM
jhc0033@gmail.com
Guest
 
Default Re: novice questions

On May 13, 12:04 am, francesco.ferr...@gmail.com wrote:

> As you can see, this has nothing to do with typedefs, which are tricks
> you can use at compile time, not at runtime. If you ever happen to
> need this in Eiffel, then you probably missed something in the design
> of your system.



I guess I don't understand how this answers my question(s). Let me
explain the "typedef" question better:

Suppose you wrote a huge program using single precision floats. Now
you want to change it to see if single precision is faster and
otherwise sufficient. How do you do it in Eiffel?

In C++, I have a

typedef double real;

and I only use "real", never "double" or "float". If I need to switch,
I change that one line above, and the whole program gets automagically
updated.
Reply With Quote
  #4  
Old 05-13-2008, 04:31 AM
Eric Bezault
Guest
 
Default Re: novice questions

jhc0033@gmail.com wrote:
> Does Eiffel (SmartEiffel) have typedefs? I want to only have to change
> one line of code to go from single precision to double precision. Only
> using an alias to double/float accomplishes that.


With ECMA Eiffel, you can instruct the compiler to consider occurrences
of REAL in your code to be either REAL_32 or REAL_64. For example, with
ISE's EiffelStudio, in the ECF file you will have to specify something
like that:

<mapping old_name="REAL" new_name="REAL_32"/>

SmartEiffel does not support ECMA Eiffel, so I don't know whether this
is possible with that compiler.

> Eiffel is meant to target super-large software projects. As I
> understand, it used to be reasonably popular. What is the most
> complicated software written in Eiffel that is still being used?


The company I work for develops and uses a set of systems currently
based on 20,000+ Eiffel classes:

http://www.eiffel.com/executives/cas...xa/study1.html

--
Eric Bezault
mailto:ericb@gobosoft.com
http://www.gobosoft.com
Reply With Quote
  #5  
Old 05-13-2008, 04:48 AM
francesco.ferreri@gmail.com
Guest
 
Default Re: novice questions

> In C++, I have a
>
> typedef double real;
>
> and I only use "real", never "double" or "float". If I need to switch,
> I change that one line above, and the whole program gets automagically
> updated.


I suppose Eric has fully answered you on this specific request; as a
general consideration: this seems to me more a "search and replace"
problem, than a software design issue, when you use typedefs you are
only instructing your compiler to add a new name to an existing type.
This is low-level manipulation, nothing to do with software design
principles you mentioned.

There are far more elegant ways of achieving this kind of flexibility
in Eiffel: you can wrap your classes, or maybe use generics, but the
best choice depends on the actual structure of your system.

Best regards,
Francesco

Best regards,
Francesco
Reply With Quote
  #6  
Old 05-13-2008, 05:11 AM
scholz.lothar@gmail.com
Guest
 
Default Re: novice questions

On 13 Mai, 15:48, francesco.ferr...@gmail.com wrote:

> I suppose Eric has fully answered you on this specific request; as a
> general consideration: this seems to me more a "search and replace"
> problem, than a software design issue, when you use typedefs you are


Well unfortunately it is not. This can't be solved with an search/
replace
in the editor.

It's nice to see that ECMA understand this problem and is trying to
solve it.
The feature is also important if you want to use mock objects during
testing
(which is a pain in the ass at the moment).
Reply With Quote
  #7  
Old 05-13-2008, 05:11 AM
Georg Bauhaus
Guest
 
Default Re: novice questions

jhc0033@gmail.com schrieb:
> Does Eiffel (SmartEiffel) have typedefs? I want to only have to change
> one line of code to go from single precision to double precision.


So in other words, either your object IS-A single precision
float or it IS-A double precision float?

Related to this,
generic components that use floats can take a float
type parameter F (F_ in SmartEiffel hairline syntax)
that is derived from some abstract general float class.
Reply With Quote
  #8  
Old 05-13-2008, 05:27 AM
Georg Bauhaus
Guest
 
Default Re: novice questions

francesco.ferreri@gmail.com schrieb:
>> In C++, I have a
>>
>> typedef double real;
>>
>> and I only use "real", never "double" or "float". If I need to switch,
>> I change that one line above, and the whole program gets automagically
>> updated.

>
> as a
> general consideration: this seems to me more a "search and replace"
> problem, than a software design issue,


Uh, whenever you start to "search and replace" types it
is a sure sign that your program might well lack some design.
(What confuses me is that you give the very advice further below.)


> when you use typedefs you are
> only instructing your compiler to add a new name to an existing type.


While in C++, typedef doesn't give you a new type, this only shows
the same issue with it has with its troublesome fundamental type system:
suppose some Eiffel has both the types REAL or DOUBLE, but does not
expose their common interface in some deferred class...

You'd want

struct my_float : public float {};

but this isn't available in C++ AFAIK. Therefore you cannot but
use a typedef or use a template parameter.


> This is low-level manipulation, nothing to do with software design
> principles you mentioned.


I think it might be proper abstraction to hide FPT details
if your algorithm does not depend on a specific FPT type, at
least not critically!

Search & Replace using language external tools (plain text editors)
does not seem to be a preferable engineering practice. Never was.


> There are far more elegant ways of achieving this kind of flexibility
> in Eiffel: you can wrap your classes, or maybe use generics, but the
> best choice depends on the actual structure of your system.


Indeed.
Reply With Quote
  #9  
Old 05-13-2008, 11:12 AM
Colin LeMahieu
Guest
 
Default Re: novice questions

The short answer is, you could using anchored types, but the follow up
question is, why would you want to?

On the surface this example makes sense although the real reason for
typedefs was for varying type sizes for the same name on different
systems and compilers. Typedefs aren't a magic switch from one to the
other. What if you pass these parameters in to an external compiled
library? The variable is truncated and expanded with each call. What
if the information is sent over the network and the writer made an
assumption of the size? That's a design mistake but it's still not an
easy one to find.

The floats->Reals example only works because they are semantically
very similar and the compiler can convert program text numbers to
either.

What if I wanted to move from floats to a BigReal class with 500
position precision? Since this no longer is a type the compiler can
directly convert from program text the example breaks down. (Although
Eiffel has a 'conversion' clause which would allow you to do this)
What if I no longer want to use floats but integers? Now the
semantics of the '/' have changes greatly and the compiler won't
complain at all since 3/2 is as valid as 3.0/2.0 but they yield very
different results.

Eiffel has a lot of other qualities that are beneficial, they're worth
some time

On May 13, 3:20 am, "jhc0...@gmail.com" <jhc0...@gmail.com> wrote:
> On May 13, 12:04 am, francesco.ferr...@gmail.com wrote:
>
> > As you can see, this has nothing to do with typedefs, which are tricks
> > you can use at compile time, not at runtime. If you ever happen to
> > need this in Eiffel, then you probably missed something in the design
> > of your system.

>
> I guess I don't understand how this answers my question(s). Let me
> explain the "typedef" question better:
>
> Suppose you wrote a huge program using single precision floats. Now
> you want to change it to see if single precision is faster and
> otherwise sufficient. How do you do it in Eiffel?
>
> In C++, I have a
>
> typedef double real;
>
> and I only use "real", never "double" or "float". If I need to switch,
> I change that one line above, and the whole program gets automagically
> updated.


Reply With Quote
  #10  
Old 05-13-2008, 11:39 AM
jhc0033@gmail.com
Guest
 
Default Re: novice questions

On May 13, 2:11 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:

> So in other words, either your object IS-A single precision
> float or it IS-A double precision float?


What about speed? If I use an ARRAY of objects that are derived from a
single precision float, will it be as fast as an ARRAY of single
precision floats (or float[] in C) ?

Note: floating point arithmetic takes a few CPU ticks, dynamic
dispatch and pointer dereferencing is 10-100 times slower.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:30 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.