Jump to content
TheOnlyOne

Need a "Delphi programming guideline"

Recommended Posts

21 hours ago, TheOnlyOne said:

using books pages with a quiz as a captcha on Windows login screen should be a good feature

I mean, this colleague as a person if not a bad guy. He fell behind with his Delphi skills it is true, but on the other hand our boss allocated in the last hour only 2 hours for discussions and refactoring. What's the point is knowing Delphi if you are not allowed to use it. Any decent project owner would know that any code needs refactoring and payment for technical debt. If the owner does not know, he should at least hire a project leader. We don't have this role. They call it that we "have a flat management organigram".

 

Anyway, even if the work was easy in this company, I decided to move away from it.

Edited by TheOnlyOne
  • Like 1

Share this post


Link to post

News. My company will close the Delphi branch and rebuild the program from scratch in React Native.
Looks like the Delphi world is getting smaller and smaller. Emba needs to work fast to shake off this "Delphi is an old grandpa" feeling.

Share this post


Link to post
39 minutes ago, TheOnlyOne said:

News. My company will close the Delphi branch and rebuild the program from scratch in React Native.

Good luck to them.

Managers don't realize what they do. The problem is not only a "Delphi is old idea" but also "Internet is beautiful, you can do anything with React" marketing.

  • Like 2

Share this post


Link to post
28 minutes ago, TheOnlyOne said:

News. My company will close the Delphi branch and rebuild the program from scratch in React Native.
Looks like the Delphi world is getting smaller and smaller. Emba needs to work fast to shake off this "Delphi is an old grandpa" feeling.

But what can they do? They have to sell their tools to stay in business, unlike many of the companies today that give away tools that support their business (Microsoft!). Their existing customer base is using Delphi mainly out of legacy requirements, so if they do anything to harm those customers or make their projects more difficult to update (bad tangents like ARC, for example), they harm their existing revenue. And if they make changes to chase modern coders (like, say, making their mobile compilers use ARC), their existing users don't benefit (at best) and those modern coders still don't have any reason to switch to Delphi.

 

I don't have a solution. I continue to use Delphi because it serves the projects we still maintain and develop well enough, and throwing out millions of lines of code to start over somewhere else is still going to be more costly than a few Delphi subscriptions.

 

The writing is on the wall, though. Delphi coders I know are planning their retirement and younger coders aren't interested in learning enough to understand real coding anyway! I just watched some guy's youtube video about how to get a job coding, and he called algorithms and data structures "theoretical" and "trick questions interviewers like to ask." The future of coding is hopeless if ridiculous stuff like that represents the industry trajectory, and anyone with an attitude like that is completely unqualified to write OOP code that requires basic memory management skills. And people who are skilled enough to write non-trivial applications in Delphi don't want the black hole on their resume that working on a Delphi application represents!

  • Like 1

Share this post


Link to post
4 hours ago, Brandon Staggs said:

younger coders aren't interested in learning enough to understand real coding anyway!

As I said before: because their Delphi code was really, really old, I proposed my boss to scratch it and start from zero.

He was reluctant, so I built it from scratch in a few days (my very private time) - needing another full month to polish the program, to make it ready to be sold - the original program is 150000 lines of code but it is procedural (all data stored in strings) and the old code was never ever deleted from the project.

On objects, that code would be rewritten in max 15000 lines!

One of the exporters they had was 8000 lines. I implemented it in mine in 60 lines (objects streamed down to binary files).

 

Now I know why my was reluctant to use my code:  because he was already convinced by other guys to rewrite it using "brand-new-shiny" web tech.

But instead of one programmer (me) and 1 month, their road map is now 10 programmers and one year. Congratulations web guys!

_

But I would have been glad if our boss had had the balls to tell us upfront (months ago) that he already decided for web-stuff and not Delphi.

 

Anyway, my CV is again ready to be submitted to companies willing to accept home-office.

Is it 4 pages (small font) too long? I don't want to cut down my libraries, scientific publications or the (industrial) robots I worked on :classic_biggrin:.

Hope to find something exciting again -> therefore, DB is pretty much excluded - Unfortunately, Delphi comes with this baggage - all still-sending companies are either running on obsolete Delphi code OR their core business involves some "god please kill now be because I am bored" DB-centric architecture.

____________________________________________________________________________________________________

But for Emba: WHY THE FUCK are you sleeping there?:classic_huh: Wake up. Hire people. Send them to Facebook, Instagram, Twitter, schools and universities. Don't forget the kindergartens! Today, they don't start teaching programming when you are 23. They start at kindergarten. My 10 years old son already knows 3 languages! Wrote game in Delphi 🙂
Start to show that Delphi is alive and kicking. Get rid of the "old guy" smell.

They hired gray beards like Marco Cantu. I thought he was one of "our" guys. Isn't he aware of what is out there? Is he so old that he doesn't know how to use the Internet?

Edited by TheOnlyOne
  • Like 1

Share this post


Link to post

As the boss/owner he can do whatever he wants with his own code and company.

15' or 150' lines, who cares as long as it works?

I also hardly know how to make a class, however my code still works very well.

Share this post


Link to post
11 hours ago, TheOnlyOne said:

Start to show that Delphi is alive and kicking

They are trying. But - unfortunately they are trying the marketing way, not the grassroot growth way. 

  • Like 1

Share this post


Link to post
Quote

Is it 4 pages (small font) too long?

Yes, it's a (very) lot. The basic rule is that the CV should not be longer than 1 page. Unfortunately, people work like this: I open a resume. I longer than 1 page. I WILL NOT READ THAT.
That's why I recommend writing it on 1 page and adding an attachment to it. If you address the reader, he will read the attachment.

Share this post


Link to post
17 hours ago, TheOnlyOne said:

News. My company will close the Delphi branch and rebuild the program from scratch in React Native.

I wish them the best of luck.

I hope the product is not of vital interest to the company.
They were somewhat between a rock and a hard place, having a legacy Delphi application with a sub par engineering team.
But rewrites (in a completely new technology) rarely go well. (At least in time and in budget).
Does your company already work with react or are they going to build a completely new engineering team, or even outsource the development?

  • Like 1

Share this post


Link to post

I hope your customers only use one version, i.e. no custom tailored versions. Furthermore I hope your boss or whoever is responsible knows every single feature, no matter how small. Because customers can get really "special" when something no longer works as expected, just because of a new version, especially one they have to pay for - assuming the rewrite will not be for free.

Share this post


Link to post
On 2/8/2023 at 6:12 AM, Skrim said:

 

Quote

As the boss/owner he can do whatever he wants with his own code and company.

Yes, you are right. It is his company. And I work there. A boss is nothing without employees. And employees tend not to follow the boss when the boss does whatever HE wants with the company..... And as I said, a boss is nothing without employees 🙂

 

Quote

15' or 150' lines, who cares as long as it works?

If you would only knew the difference (in efficiency and stability) between procedural and OOP....
I spent 2 weeks in some super convoluted procedural program they have (an exporter, 8000 lines), to fix 17 bugs. Another 3-4 to fix.
In the new version, OOP, I rewrote that that exporter in under 60 lines of code.

 

Quote

I also hardly know how to make a class, however my code still works very well.

Every line of code we write, increases the chances to introduce a bug. Procedural code tent to be way way way more "verbose", and separate poorly the program logic....

You see where I am going with this... right?

 

Edited by TheOnlyOne

Share this post


Link to post
On 2/8/2023 at 9:32 AM, Stano said:

Yes, it's a (very) lot. The basic rule is that the CV should not be longer than 1 page. Unfortunately, people work like this: I open a resume. I longer than 1 page. I WILL NOT READ THAT.
That's why I recommend writing it on 1 page and adding an attachment to it. If you address the reader, he will read the attachment.

Thanks!

It is hard to cut it down. I worked on so make project and in so many industries (robotics, PC hardware, electronics, bioinformatics, medical, ecommerce, etc).

But I will try to cut it down.

 

Edited by TheOnlyOne

Share this post


Link to post
11 hours ago, TheOnlyOne said:

Yes, you are right. It is his company. And I work there. A boss is nothing without employees. And employees tend not to follow the boss when the boss does whatever HE wants with the company..... And as I said, a boss is nothing without employees 🙂

 

If you would only knew the difference (in efficiency and stability) between procedural and OOP....
I spent 2 weeks in some super convoluted procedural program they have (an exporter, 8000 lines), to fix 17 bugs. Another 3-4 to fix.
In the new version, OOP, I rewrote that that exporter in under 60 lines of code.

 

Every line of code we write, increases the chances to introduce a bug. Procedural code tent to be way way way more "verbose", and separate poorly the program logic....

You see where I am going with this... right? 

 

60/8000 how can that be possible 🙂

 

Sounds like it was a showmessage('Are you sure...'); showmessage('Are you really sure...'); showmessage('Are you absolutely sure...');

 

I quess both OOP and procedural style can be structured badly.

 

However, my program started it's life in 2005 and at that time I had no clue what OOP was. I have looked into it, but find it somehow confusing and hard to learn. My program is an accounting suite, I have separated into units where each unit does a specific task and the unit is named accordingly. There are hundreds and hundreds of units, no problem there. You will not be able to write that program in 60 lines or even 60' lines 🙂

Share this post


Link to post

If I remember correctly, he did not write about the program. But about the only functionality. There was already a problem with the data structure. Everything else followed from that. Plus work, thinking of a programmer.

Share this post


Link to post
13 hours ago, Skrim said:

60/8000 how can that be possible 🙂

Absolutely possible. No exaggeration. Actually, if I count the lines, it will be much much lower than 60. I just didn't want to exaggerate. I will go count the lines today 🙂

 

The guy that wrote that financial exporter (to CSV) was keeping his quite complex data in some kind of text file (that contains all binary data converted to strings). He invented his own format, some kind of CSV/XML (with files inside the file), using special characters as end of record/end of line/end of file markers. Writing the data to disk in such format takes a lot of code. Then opening the files from an external tool takes again A LOT of parsing up and down to extract specific data fields, from specific addresses, a lot of code. So, no wonder he ended up with 8000 lines of code.

 

What I do in my new program, I keep my data (NATURALLY) in objects and stream down the objects to disk, to binary files. All this code comes naturally with all my objects.

When the time came to export the financial data from those objects, I simply enumerate all objects and pick the fields/properties that I need and save them as CSV, for the end user.

No more poking around to find specific data in an over-complex TXT file.

Nothing fancy, just something like:

   for var Object in MyObjects do

      Result:= Result+ Object.FieldsXYZ+ ',' + CRLF;

 

So, my advice for you: if you think that objects will drag you down, think twice!
Do watch a tutorial, or look at some Delphi code on GitHub, or look at the Delphi source code.

It will change your life! It will change your code!
Today, I cannot imagine myself writing code without OOP!

 

This old procedural program that I rewrote as OOP, it was reduced to 10% (as SLOC). Long live the objects 🙂  :classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader::classic_cheerleader:

 

 


 

 

 

Edited by TheOnlyOne

Share this post


Link to post

We must remember that, when using ready-made classes/object, we are actually leaving out coding because someone has already done it for us, so it is no exaggeration to say that 80 lines of code can replace 8000.

 

Of course, at first glance, it's an exaggeration! But it's no exaggeration if the previous programmer created a "frankenstein" in his code...

thus, 8000 dead body parts, when checked in "loco", could turn into just a few actual organs!

 

So, it shouldn't be any exaggeration! But just a statement of what was not seen before, due to lack of knowledge, or negligence!

 

After all, if you don't code, someone else will have to do it for you! Even if it's "ChatGPT" or "Bard"...  :classic_biggrin: 😛

Share this post


Link to post
11 hours ago, TheOnlyOne said:

I keep my data (NATURALLY) in objects and stream down the objects to disk, to binary files. All this code comes naturally with all my objects.

Interesting, is it common practice to use Delphi-specific object streaming to store data? What if object structure changes?

Share this post


Link to post
5 hours ago, Fr0sT.Brutal said:

Interesting, is it common practice to use Delphi-specific object streaming to store data?

You have to store your data somewhere right?

Could be registry, text file, DB. etc. I choose binary files because you save your data "as it is".  No need to convert back and forth from (for ex) TDateTime to string and then back. You just save the TDateTime as it is (double, I think). That's it!

 

Quote

What if object structure changes?

You use "padding".
At the end of your file, you keep something like 64 bytes empty. You can put later whatever you want there. Make the padding large if you know your Object is still under design and it will change.
If your object changes dramatically, you use file versioning: each binary file has a header. You detect which file version the user presents to you and you load the appropriate decoder for that version.

I used this for the last 20 years. 1 gazillion times faster than a DB. Easy to write. No more conversions between data types.

I have some libraries for that https://github.com/GodModeUser

 

This is for ex a list of orders (TOrders). It will save/load all orders in the list. The TOrder is quite complex but the streaming is handle just by one line of code (load/save).
 

{-------------------------------------------------------------------------------------------------------------
   I/O STREAM
-------------------------------------------------------------------------------------------------------------}
procedure TOrders.Load(IOStream: TCubicBuffStream; Drivers: TObject; Products: TProducts);
VAR
   i, iCount: Integer;
begin
  Assert(Drivers  <> NIL);
  Assert(Products <> NIL);

  if IOStream.ReadHeader(StreamSignature) <> 1
  then RAISE Exception.Create('Invalid TOrders header!');
  iCount:= IOStream.ReadInteger;           { Total items in this list }
  IOStream.ReadPadding(1024);

  { Write each orders }
  for i:= 0 to iCount-1 DO
   begin
    VAR Order:= CreateNewOrder;
    Order.Load(IOStream);

   end;
end;


procedure TOrders.Save(IOStream: TCubicBuffStream);
VAR
   i: Integer;
begin
  IOStream.WriteHeader(StreamSignature, 1);  { Local header }
  IOStream.WriteInteger(Count);              { Total items in this playlist }
  IOStream.WritePadding(1024);

  { WRITE EACH ITEM }
  for i:= 0 to Count-1
    DO Self[i].Save(IOStream);
end;

 

See how I reserve space for the future with  WritePadding/ReadPadding.
Also observe the Header of the file (StreamSignature) followed by version umber (1).

 

Easy-peasy, instant objects to file 🙂

 

Edited by TheOnlyOne
  • Thanks 1

Share this post


Link to post
19 hours ago, TheOnlyOne said:

I used this for the last 20 years. 1 gazillion times faster than a DB. Easy to write. No more conversions between data types.

I have some libraries for that https://github.com/GodModeUser

Thanks, good to know that. I prefer standardized formats for simple interoperability but likely there are cases where such Delphi-only solutions could win.

Share this post


Link to post
2 hours ago, Fr0sT.Brutal said:

simple interoperability

I don't intend to share my delphi objects with other languages. in this case, a binary file is the most efficient, and safe and easy solution.

🙂

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×