Recent

Author Topic: TP legacy shiitcode  (Read 10665 times)

Weiss

  • Full Member
  • ***
  • Posts: 231
TP legacy shiitcode
« on: April 30, 2024, 04:16:01 am »
Not the first time I am trying to use some ancient TP code, and naturally wonder if back in a day they could read what they wrote. Everything, beginning from naming variables, to user input validation (often none) hold no water. Scarce comments, or no comments. Needless copying of arrays. I am very new myself, but that code is written by PhD and such.

And, code published in articles sometime definitely never been compiled, because it contain errors, syntax and logic errors as well. Sometimes I can unwind the logic and see what was meant, and re-write. But then I wonder, if article was published and being referenced in other work, how come no one reviewed for 30 years?

440bx

  • Hero Member
  • *****
  • Posts: 6093
Re: TP legacy shiitcode
« Reply #1 on: April 30, 2024, 04:37:39 am »
how come no one reviewed for 30 years?
A number of possibilities come to mind.  Among them:

1. those who reviewed it found the code to be "fine", they would have coded it the same way (or maybe worse.)

2. those who reviewed it found the code atrocious (as you apparently did) but, figured that they would keep their mouths shut because criticism isn't always welcome.

3. they have a PhD in computer science with a minor in covfefe from trump university and the whole thing went so far above their head international space station folks sighted a ufo.

One important thing to keep in mind: just because something is published doesn't mean it's any good. 
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: TP legacy shiitcode
« Reply #2 on: April 30, 2024, 07:26:06 am »
It can't be that bad without seeing code.
But I am afraid that I also wrote silly code in ucsd/apple pascal for a curriculum I gave at university: introduction in programming for social science students in 1980/81.
Code: Pascal  [Select][+][-]
  1. program ucsdpas;
  2. { this is not from my curriculum, it demo's an often seen error from the time }
  3. var
  4. count: integer;
  5. label
  6. StartLoop;
  7. begin
  8. count := 1;
  9. goto StartLoop;
  10. {2024 comment: This part of the code will never be executed }
  11. writeln('This line will not be printed, silly.');
  12. StartLoop:
  13. writeln('Count: ', count);
  14. count := count + 1;
  15. if count <= 5 then
  16. goto StartLoop;
  17. writeln('Loop finished.');
  18. end.
Goto's everywhere, a necessity, bad formatting (lack of indentation), some but not extensive validation of input and output, wrong choice in program flow by not examining what codeblock was executed most, which is a logic error, etc. some but sparse comments because the code was explained in an external booklet that came with it, explaining functional design and program flow, flowchart. Not yet any real modelling.
On the other hand, that was also due to language limitations at the time.
Then came TP1, with which you could write all kind of trickery because the compiler wasn't very strict (that's mild). So we wrote code using that trickery, just because we could!, like self modifying code and stack trickery.
From TP3 onwards things started to improve: the more people used it, the better the standards regarding code and comments improved.
Then came TP5.5 - TP7 with its quirky, still supported halfway OOP, that initially few understood, but modelling became quite common(by hand).
In the Delphi era, we became much more used to - a much more mature - OOP and things improved considerably with tools like modelmaker with its at the time unrivalled support for code generation based on documentation and an uml description to generate the program body. Certainly in a professional environment the future started to look bright. But bad code is of all times, we see it daily.
In summary: what now looks like bad code from yesteryear is partly due to language limitations. But also evolving programming paradigms, which in turn lead to bad programming because of over-use of components in Object Pascal.(sigh)
Code: Pascal  [Select][+][-]
  1. //recenty seen, simplified:
  2. TBeepComponent=class(Tcomponent);
  3. private
  4. public
  5.   procedure beep;virtual;
  6. end;
  7. procedure TBeepComponent.Beep;
  8. begin
  9.    system.Beep;
  10. end;
A slight relief may be that programmers in other languages were even worse: BASIC, C. Forth.
And some much better, in my case, Fortran and COBOL.
I still love COBOL because of its structure, almost self-documenting.
i also still use it: many a phone call to fix COBOL issues because people know I am proficient in COBOL. (very well payed, btw)
« Last Edit: April 30, 2024, 11:51:11 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Joanna

  • Hero Member
  • *****
  • Posts: 1418
Re: TP legacy shiitcode
« Reply #3 on: April 30, 2024, 11:29:50 am »
Maybe the TBeepComponent=class(Tcomponent)
Could be used to replace the standard beep with other sounds?

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: TP legacy shiitcode
« Reply #4 on: April 30, 2024, 11:32:33 am »
Yes in system.OnBeep. But this component is an example of the silly over-use of components...
Programmers don't need them, screen drawers love them, they can't help themselves but it is bad coding. Worse if you register it for design time on the components panel...
« Last Edit: April 30, 2024, 11:37:12 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

cdbc

  • Hero Member
  • *****
  • Posts: 2621
    • http://www.cdbc.dk
Re: TP legacy shiitcode
« Reply #5 on: April 30, 2024, 12:42:35 pm »
Hi
YES Thaddy, Hear hear +1
Sometimes we see code here, that make my toes curl & my eyes water  :(
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TP legacy shiitcode
« Reply #6 on: April 30, 2024, 01:41:11 pm »
Not the first time I am trying to use some ancient TP code, and naturally wonder if back in a day they could read what they wrote. Everything, beginning from naming variables, to user input validation (often none) hold no water. Scarce comments, or no comments. Needless copying of arrays. I am very new myself, but that code is written by PhD and such.
It has been a while but yes I certainly remember such legacy code.

Terrible to read/watch, obviously written with one mindset in mind and 9 out of 10 times did not compile at all due to errors. What is even worse, at least by looking at some of the posts here, is that there seem to be a revival of such badly written code.

Don't forget that back in the day it was all hot and buzz. Similar as the AI buzz these days and which has many people who do not know any shiite about the topic think they need to publish something about it, e.g. a simple history repeats with capitalism at its best  :)
Today is tomorrow's yesterday.

Joanna

  • Hero Member
  • *****
  • Posts: 1418
Re: TP legacy shiitcode
« Reply #7 on: April 30, 2024, 03:01:48 pm »
Yes in system.OnBeep. But this component is an example of the silly over-use of components...
Programmers don't need them, screen drawers love them, they can't help themselves but it is bad coding. Worse if you register it for design time on the components panel...
I consider controls that can be placed at design time a feature to assist people new to using Lazarus. It’s much easier to create at runtime.

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: TP legacy shiitcode
« Reply #8 on: April 30, 2024, 04:46:04 pm »
It is also much easier to learn bad habits.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

domasz

  • Hero Member
  • *****
  • Posts: 616
Re: TP legacy shiitcode
« Reply #9 on: April 30, 2024, 08:41:01 pm »
But then I wonder, if article was published and being referenced in other work, how come no one reviewed for 30 years?

Maybe other people found the bugs so easy to fix they considered the code good enough.
Maybe they read the description of the algorithm and coded themself.

teos

  • Full Member
  • ***
  • Posts: 161
Re: TP legacy shiitcode
« Reply #10 on: April 30, 2024, 10:31:37 pm »
It is also much easier to learn bad habits.

I don't agree but I guess you speak in general. Components are a way of distributing building blocks. You don't need to know how a TDataset works and how DBF indexes are set up when you drop a TDBF component on your form.
I am very happy that I don't had to figure out TCP/IP or email protocols but just can drop an Indy component on a form.


TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TP legacy shiitcode
« Reply #11 on: May 01, 2024, 01:18:47 am »
I don't agree but I guess you speak in general. Components are a way of distributing building blocks. You don't need to know how a TDataset works and how DBF indexes are set up when you drop a TDBF component on your form.
I am very happy that I don't had to figure out TCP/IP or email protocols but just can drop an Indy component on a form.
Then, allow me to be the one that disagrees with that  :)

Components are not the answer to that as they (also) add redundant overhead. A class/object is suffice.

Besides that and as shown on the forum many people (read newcomers but I have also witnessed that with seasoned programmers) have no clue whatsoever how setting properties and events influences the behaviour of these components. This is especially true for databases and often seem to lead to confusion.

If you have to maintain bigger projects then relying on streamed settings is no fun at all and makes things much more difficult than it has to be.

Components are imho good for one thing and one thing only and that is designing a GUI (and even that is debatable because I personally dislike current implementation based on old school GUI design) . The moment you start using components for something else it becomes tiresome and are merely a distraction.

And quite frankly and as I understand it, that is exactly the kind of habit Thaddy was referring to.

2 cents
« Last Edit: May 01, 2024, 01:23:50 am by TRon »
Today is tomorrow's yesterday.

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: TP legacy shiitcode
« Reply #12 on: May 01, 2024, 11:00:26 am »
Exactly. There are few cases that non-visual components actually contribute to better code, but maybe the database components are an exception because of all the connectors you do not have to set in code. Although I usually create even these in code. There are a few more that are acceptable to me along the same line - many connectors - , like some audio component packages, like ACS.
« Last Edit: May 01, 2024, 11:02:02 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Joanna

  • Hero Member
  • *****
  • Posts: 1418
Re: TP legacy shiitcode
« Reply #13 on: May 01, 2024, 01:48:31 pm »
It is also much easier to learn bad habits.
I’m not sure what bad habits you are referring to but I’ve found that Putting gui controls directly onto form is a good way to get familiar with what they do because it’s easy to look at events and properties in object inspector. Having it placed upon the form also allows the autocomplete popup menu to show everything possible for it.

Handoko

  • Hero Member
  • *****
  • Posts: 5515
  • My goal: build my own game engine using Lazarus
Re: TP legacy shiitcode
« Reply #14 on: May 01, 2024, 03:40:29 pm »
I’ve found that Putting gui controls directly onto form is a good way to get familiar with what they do because it’s easy to look at events and properties in object inspector.

Thaddy's Beep example is a perfect example that is no need for making it a component, it has no property and only a single method.

Having it placed upon the form also allows the autocomplete popup menu to show everything possible for it.

You don't have to place it on the form. On your code editor you can use ctrl + space shortcut to active that feature.

Components are not the answer to that as they (also) add redundant overhead. A class/object is suffice.

This is very true. Computer hardware nowadays has become increasingly powerful. Perhaps too powerful, many programmers forget how to write lightweight code. While I agree Joanna said that placing controls at design time can be more beginner friendly. But too much sugar coated isn't good. I remember I started to learn programming on my extremely slow computer. That was really painful. I abandoned BASIC to force myself to learn and use Pascal because Pascal is lightweight and fast. I now still keeping the habit to write efficient and lightweight code.

In my personal projects, I rarely put controls on the forms. I currently working on a paid project that needs database connection. All the things are done by using code. I have written many classes, units and modules for graphics, OpenGL, UI and others. I don't make them controls, which can be dropped on forms.

Making them controls is only good for 'others' to use it. Switch between the code editor and form view to select the control and click the property is no fun if you're working on a large project. So because I access the components by using code, I can use ctrl + F feature to find something quickly and edit it, my hands are keep on they keyboard no need to touch the mouse.

As TRon said, components (that can be put on a form) are good when design a GUI.

Beginners should always challenge themselves to do something harder. That's a good thing to do to level up their skills. Joanna, try to write a GUI program without dropping any visual controls on the form. That's hard if you're beginner, but once you can do things all by code, you won't use the old method.

If you want to learn, this is how to create a form on runtime:
https://forum.lazarus.freepascal.org/index.php/topic,52725.msg389274.html#msg389274

As you can see, if you want to change or edit something that can be easily done without switch to the form view. If you ever working in a large project, you will understand why it is important.

 

TinyPortal © 2005-2018