A couple of questions regarding class design

On 22.04.2008 21:12, Michael W. Ryder wrote:

I haven’t felt the need for a goto in ages. I also rarely use
continue and break in loops. My impression is that quite a number of
cases where either is chosen can be greatly improved and actually
simplified by choosing a different loop condition. My 0.02EUR…

Coming from a background in computers from the 70’s when the language
was much closer to the metal I never had any problems with Go To or
Jump.

Well, you had to use what you got, didn’t you? I believe the reasons
Basic et al had GOTO was historic as you said: programming languages did
not have evolved very far from the basis (machine code or assembler if
you will).

But later people detected deficiencies of this approach and tried to
come up with better solutions. I would not want to miss structured
programming and exceptions.

In assembler there is no way to not use Jumps for loops or
conditional processing. Fortran and Basic were much the same way. I
believe Knuth’s original works were from this era and of course a lot of
his code is in the MIX assembler.
I can see the reason to eliminate jumping around in code when possible
but think they can sometimes make a program easier to read. I find it
easier to read a program that says “If error goto ERROR” over trying to
figure out where a Break command goes.

Well, for error handling there is a different mechanism in modern
languages: exceptions. :slight_smile:

Kind regards

robert

On 23.04.2008 00:44, Robert D. wrote:

On Tue, Apr 22, 2008 at 10:55 PM, Michael W. Ryder
[email protected] wrote:

Most of my programming is for business use. A lot of the time the user
will make an entry and depending on what they enter the program will
continue or jump to a totally different area. While it may be possible to
do with a couple of different entries to eliminate the jumps I don’t think
it makes the code any more readable, and after that it is almost impossible.
I did manage something like this in C using a case statement to determine
what function to call next but Business Basic does not have this ability.

Well without the code I cannot really help but somehow I have the
feeling that send might be your friend here!

Now Michael just needs to integrate the Ruby interpreter into his
Business Basic engine. :slight_smile:

Cheers

robert

On Wed, Apr 23, 2008 at 8:05 AM, Robert K.
[email protected] wrote:

Now Michael just needs to integrate the Ruby interpreter into his Business
Basic engine. :slight_smile:
Have you given up hope for him already :wink: ?
R.


http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

2008/4/23, Robert D. [email protected]:

On Wed, Apr 23, 2008 at 8:05 AM, Robert K.
[email protected] wrote:

Now Michael just needs to integrate the Ruby interpreter into his Business
Basic engine. :slight_smile:

Have you given up hope for him already :wink: ?

Hey, I didn’t say he can’t do it. :slight_smile:

robert

On Wed, Apr 23, 2008 at 11:47 AM, Robert K.
[email protected] wrote:

Hey, I didn’t say he can’t do it. :slight_smile:
Just to be clear, I meant to join Ruby, not that he could not program,
hopefully that was not misunderstood :open_mouth:
R.

2008/4/23, Robert D. [email protected]:

Have you given up hope for him already :wink: ?

Hey, I didn’t say he can’t do it. :slight_smile:

Just to be clear, I meant to join Ruby, not that he could not program,
hopefully that was not misunderstood :open_mouth:

Oh no, not at all - at least here. :slight_smile:

“Great Roberts think alike.”
cough, cough

Now off to CL watching…

robert

On Wed, Apr 23, 2008 at 7:29 PM, Robert K.
[email protected] wrote:

Now off to CL watching…
Common Lisp that is I hope :wink:
R.

http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Robert K. wrote:

it makes the code any more readable, and after that it is almost
Business Basic engine. :slight_smile:

Funny you should mention that. One of the things I am working on is
Ruby equivalents to the Business Basic commands. Obviously some of it
is not going to be possible, like the built in file and screen handling,
and will require integration with other tools. From this I can try to
convert some 20+ years of programs to Ruby and get some of the benefits
of the language.

2008/4/23, Michael W. Ryder [email protected]:

One thing I haven’t figured out is returning from an exception to the
calling location. In Business Basic I can set a location that the program
will go to when an untrapped error occurs. From there I can handle the
error and return back to the program.
I can also do the same if the Escape key is pressed, or I can go to a new
location and continue. This comes in real handy when an operator is
finished with data entry they just press the Escape key to save the changes
and continue.

That would be “retry”:

irb(main):009:0> def test(x) raise “#{x} is too low” if x < 5 end
=> nil
irb(main):010:0> i = 0
=> 0
irb(main):011:0> begin; puts i; test i; rescue Exception => e; puts e;
i+=1; retry; end
0
0 is too low
1
1 is too low
2
2 is too low
3
3 is too low
4
4 is too low
5
=> nil
irb(main):012:0>

Kind regards

robert

Robert K. wrote:

And, does it feel better? For me it does - for Knuth apparently
not have evolved very far from the basis (machine code or assembler if
I can see the reason to eliminate jumping around in code when possible
but think they can sometimes make a program easier to read. I find it
easier to read a program that says “If error goto ERROR” over trying
to figure out where a Break command goes.

Well, for error handling there is a different mechanism in modern
languages: exceptions. :slight_smile:

One thing I haven’t figured out is returning from an exception to the
calling location. In Business Basic I can set a location that the
program will go to when an untrapped error occurs. From there I can
handle the error and return back to the program.
I can also do the same if the Escape key is pressed, or I can go to a
new location and continue. This comes in real handy when an operator is
finished with data entry they just press the Escape key to save the
changes and continue.

On Thu, Apr 24, 2008 at 11:05 PM, Robert K.
[email protected] wrote:

On 23.04.2008 19:48, Robert D. wrote:

Well in our match of wit (very modest as I am) I declare you the winner.
Robert vs. Robert 1 - 0
Cheers
Robert (what else)


http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

On 25.04.2008 09:03, Robert D. wrote:

On Thu, Apr 24, 2008 at 11:05 PM, Robert K.
[email protected] wrote:

On 23.04.2008 19:48, Robert D. wrote:

Well in our match of wit (very modest as I am) I declare you the winner.
Robert vs. Robert 1 - 0

That’s just an intermediate result - wait for the 2nd half. I am sure
you have some tricks left. Thank you for the inspiration!

Cheers
Robert (what else)

Did I just talk to myself? Oh, I need a break…

Have a great weekend - weather will be fine!

robert

On 23.04.2008 19:48, Robert D. wrote:

On Wed, Apr 23, 2008 at 7:29 PM, Robert K.
[email protected] wrote:

Now off to CL watching…
Common Lisp that is I hope :wink:

Of course, with 22 actors and one controller. A complex application
with a load of observers. It’s real time application: the whole
processing has to complete within 90 minutes (plus some slack for
special cases). Unfortunately they did not get rid of punch cards yet
and to make matters worse they have two different kinds of these cards.
That’s also the reason why sometimes there are drop outs and not all
processors continue processing until the end. Bugs creep into every
program - even if it’s written in Lisp and uses a friendly green screen.

:slight_smile:

robert

On 26.04.2008 01:29, Simon K. wrote:

haven’t felt the need for a goto in ages. I also rarely use continue
and break in loops. My impression is that quite a number of cases where
either is chosen can be greatly improved and actually simplified by
choosing a different loop condition. My 0.02EUR…

Tell that Matz & Co.

,----[ ruby-1.9$ grep -c goto *.c | grep -v 0 ]

Last time I checked C did not have exceptions. Without looking at the
exact locations that fact alone might attribute for quite a few of them:

File ruby/ext/openssl/ossl_ocsp.c
5 100.00% err

File ruby/ext/openssl/ossl_pkcs12.c
3 100.00% err

File ruby/ext/openssl/ossl_pkcs7.c
3 100.00% err

File ruby/bignum.c
8 72.73% bad
1 9.09% bignum
1 9.09% bigparse
1 9.09% out_of_range

“goto”, “break” et al aren’t bad in itself like to tool is, but it is
like a sharp knife which can do damage more easily when handled
carelessly than an edgeless knife. Also, often a sharp knife is not the
right tool either, like, when you want to fasten a screw.

I do say though that a lot of code I see (and have to change) has
“break” and “continue” in there and becomes easier to read and
understand once you take them out. I do have to concede that in the
past of my company there was one guy who wrote exceptionally bad code.

Looking a bit further at label counts in goto.c:

File ruby/regex.c
39 51.32% fail
4 5.26% numeric_char
4 5.26% invalid_escape
4 5.26% nofinalize
3 3.95% end_of_pattern
3 3.95% restore_best_regs
3 3.95% repeat
3 3.95% normal_char
2 2.63% too_big
2 2.63% memory_exhausted
2 2.63% invalid_pattern
1 1.32% nested_meta
1 1.32% on_failure
1 1.32% unfetch_interval
1 1.32% advance
1 1.32% startpos_adjust
1 1.32% begbuf_match
1 1.32% range_retry

Of course, a state machine is special in a way. Like a parser, which is
typically generated:

File ruby/parse.c
6 8.70% decode_num
6 8.70% trailing_uc
5 7.25% retry
4 5.80% again
4 5.80% eof
3 4.35% yyerrlab
3 4.35% yynewstate
3 4.35% error
3 4.35% yyoverflowlab
2 2.90% yyerrorlab
2 2.90% yyerrlab1
2 2.90% id_regist
2 2.90% gvar
2 2.90% quoted
2 2.90% ternary
2 2.90% yyreduce
2 2.90% escaped
2 2.90% yybackup
2 2.90% yyreturn
2 2.90% id
2 2.90% yydefault
1 1.45% yysetstate
1 1.45% new_id
1 1.45% quotation
1 1.45% yyacceptlab
1 1.45% yyabortlab
1 1.45% start_num
1 1.45% octal_number
1 1.45% newline

If you want to do it yourself, here’s the quickly hacked gotolyzer™:

Robert@Babelfish2 /c/TEMP
$ cat gotolyzer.rb
#!/bin/env ruby

ARGV << “.” if ARGV.empty?

ARGV.each do |dir|
Dir[dir + “/**/*.{h,c}”].each do |file|
cnt = Hash.new 0
File.read(file).scan(%r{\bgoto\b\s+([^\s;]+)}) do |m|
cnt[m] += 1
end
unless cnt.empty?
puts “File #{file}”
sum = 0
cnt.sort_by {|k,v| sum += v; -v}.each do |label, count|
printf “%5d %5.2f%% %s\n”, count, count * 100.0 / sum, label
end
puts
end
end
end

Robert@Babelfish2 /c/TEMP
$

You couldn’t do that as elegantly and shortly in C. That’s the kind of
sacrifice Phlip mentioned.

Cheers

robert

and break in loops. My impression is that quite a number of cases where
either is chosen can be greatly improved and actually simplified by
choosing a different loop condition. My 0.02EUR…

Tell that Matz & Co.

,----[ ruby-1.9$ grep -c goto *.c | grep -v 0 ]
| array.c:2
| bignum.c:11
| class.c:4
| compile.c:18
| dir.c:5
| dln.c:32
| eval.c:3
| file.c:2
| gc.c:12
| io.c:15
| marshal.c:5
| numeric.c:1
| object.c:5
| pack.c:6
| proc.c:1
| process.c:2
| random.c:3
| range.c:2
| re.c:4
| regcomp.c:43
| regerror.c:1
| regexec.c:157
| regparse.c:94
| ruby.c:16
| signal.c:6
| sprintf.c:16
| string.c:8
| thread.c:3
| time.c:5
| util.c:92
| variable.c:3
`----

mfg, simon … l