Who to qualify this ?

22 views
Skip to first unread message

Jacques Silberstein

unread,
Mar 16, 2018, 3:09:44 PM3/16/18
to eiffel...@googlegroups.com
Who to qualify this ?

From class LINEAR

linear_representation: LINEAR [G]
-- Representation as a linear structure
do
Result := Current
end

Most descendant doesn't redefine that feature. But from
CONTABLE_SEQUENCE the implementation of index is an INTEGER attribute.
This make that any client of a linear_representation manipulate the
supplier of that representation it-self. And in general move the
cursor. This is a well masked bord effect. And, the client thing that
has no consequences while this is just a representation !
I thing, one should replace that by:

linear_representation: LINEAR [G]
--
Representation as a linear structure
do

Result := twin
end


Bertrand Meyer

unread,
Mar 16, 2018, 3:17:30 PM3/16/18
to eiffel...@googlegroups.com, me...@inf.ethz.ch

(bord effect à side effect)

 

Your point seems to be correct. But I would be wary of introducing hidden performance hits that might affect lots of existing software. I can already see the complaints.

 

My guess is that EiffelBase has other cases deserving criticism, from a correctness perspective, in EiffelBase. For a revised version of the library that is entirely designed for correctness, and has been fully proved correct, it is worthwhile looking into EiffelBase 2.

 

But you are right, descendants of LINEAR in EiffelBase should take care to redefine linear_representation.

 

-- BM

 

 

-----Original Message-----
From: eiffel...@googlegroups.com [mailto:eiffel...@googlegroups.com] On Behalf Of Jacques Silberstein
Sent: Friday, March 16, 2018 20:10
To: eiffel...@googlegroups.com
Subject: [eiffel-users] Who to qualify this ?

 

Who to qualify this ?

 

From class LINEAR

 

                linear_representation: LINEAR [G]

                                                -- Representation as a linear structure

                                do

                                                Result := Current

                                end

 

Most descendant doesn't redefine that feature. But from CONTABLE_SEQUENCE the implementation of index is an INTEGER attribute.

This make that any client of a linear_representation manipulate the supplier of that representation it-self. And in general move the cursor. This is a well masked [side] effect. And, the client thing that has no consequences while this is just a representation !

I thing, one should replace that by:

 

                linear_representation: LINEAR [G]

                                                --

Representation as a linear structure

                                do

                                               

Result := twin

                                end

 

 

--

You received this message because you are subscribed to the Google Groups "Eiffel Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.

Visit this group at https://groups.google.com/group/eiffel-users.

For more options, visit https://groups.google.com/d/optout.

Finnian Reilly

unread,
May 11, 2018, 4:27:35 AM5/11/18
to Eiffel Users
A choice: Performance or Correctness
The professor is correct, if the linear_representation was changed for correctness, people would be up in arms over the performance hit. As a library designer I recently had the idea "why not offer users the choice whether they want correctness or performance". You can do this with a simple boolean variable `keeping_ref'. Take for example this routine found in class EL_UTF_8_ZCODEC

    as_unicode (utf_8: STRING; keeping_ref: BOOLEAN): READABLE_STRING_GENERAL
       
-- returns `utf_8' string as unicode
        -- when keeping a reference to `
Result' specify `keeping_ref' as `True'
        local
            str_32: STRING_32
        do
            if is_single_byte_utf_8 (utf_8) then
                Result := utf_8
            else
                str_32 := Unicode_buffer
                str_32.wipe_out
                utf_8_string_8_into_string_32 (utf_8, str_32)
                Result := str_32
            end
            if keeping_ref then
                Result := Result.twin
            end
        end


This routine is potentially dangerous as it returns a reference to a shared instance. But if all you are doing is appending the result to another string, there is no point in twinning the result which adds a lot of unnecessary overhead. The fact of having this argument alerts the user to potential pitfalls.


Reply all
Reply to author
Forward
0 new messages