Jump to content
algodritmo

Code feedback

Recommended Posts

Hi, I was wondering if I could get some honest opinion about some Delphi code. We're presented with the option of selling a Windows app, Delphi code. I'm attaching the main 2 Pas files.

It's for a simulation model of cow digestion, but it doesn't have any documentation at all, of the model or the code or anything. We just know that the results are good.

If someone could have a really quick glance at the code I'd love to know how long do you think it would take an experienced programmer to be able to understand it, reverse document it, eventually even extract parts of the model to some other software, or modify the current software, etc. Apart from the code logic itself, would it be possible to infer the logic of the cow model behind it?

How much work all of that would be?

Thank you soooo much!

https://pastebin.com/nuPJHrKd

https://pastebin.com/uy1kByAk

Share this post


Link to post

I don't have to judge it. Out of curiosity, I looked at it. So fast.

  • Nobody will go with your text formatting. It can't be read😤
  • Declaring variables, given their huge number, I would put in a separate unit (Classes?)
  • You are initializing variables. It should be a separate function. In your case, in a separate unit.

You must clear that code first.

Edited by Stano

Share this post


Link to post
11 minutes ago, Stano said:

I don't have to judge it. Out of curiosity, I looked at it. So fast.

  • Nobody will go with your text formatting. It can't be read😤
  • Declaring variables, given their huge number, I would put in a separate unit (Classes?)
  • You are initializing variables. It should be a separate function. In your case, in a separate unit.

You must clear that code first.

Well I understand you, but that was the idea of the question in fact... trying to guess how much work would it be to go from "it can't be read", to "well now we understand it", "we can present some high level documentation (related to the cow model, not to the code itself)", etc.

Share this post


Link to post

BTW, I have some coding skills, and for me that's looks like a months long task, if at all possible. But the developer of that code says that it would be simple for an experienced Delphi programmer, so we're tying to find more opinions 🙂 

Those are just 2 of the files of course. It's a GUI project, with local and remote DB access, charts, etc. But those are the main ones.

Edited by algodritmo

Share this post


Link to post

I think that the actual modification of the code into a readable form is max for one day.

Share this post


Link to post
Guest

Me,too. Scrolled about for some minutes.

First off; what are the use cases, how many clients / what revenue. 

Is it a project where i get payed per hour or do i have to wait for revenue (comission).

No... no no no, i do not see a good path, paying someone 20-40 hours.

For UNDERSTANDING IMHO you should "engage" someone that feel comfortable both with the legacy code and the "future plans".

My client sometimes engage other when they feel i change to much, they often have to come back to me (for a higher price) after those "cheap excursions" int "cheaper".

My take: evaluate seriously whet this project might give back and ditch it if someone with insight would be "too expensive".

IMHO

Share this post


Link to post
Guest

@Stano, the OP wrote that the presented files are "just two but the main part". If you read code like you read posts, then i would not give you the job. Do you really feel you know at this momen what the other (non presented parts) entail? This is not a one-off, this is a process.

Share this post


Link to post
Guest

@algodritmo, after a meeting of around two hours, i could probably state the prerequisites for putting my head into this.

But no guarantees at all. and i would not be able to start before april IF i deem you budget sufficient and IF my current clients do not fuck up before that (they usually do).

Share this post


Link to post
Quote

@Stano, the OP wrote that the presented files are "just two but the main part". If you read code like you read posts, then i would not give you the job. Do you really feel you know at this momen what the other (non presented parts) entail? This is not a one-off, this is a process.

But that was after my answer :classic_smile: I already mentioned here that I am not a programmer. I'm just playing with him :classic_biggrin:

  • Sad 1

Share this post


Link to post

Such a small insignificant thing. Typical for me. I only meant formatting/refactoring published files.

Share this post


Link to post

The source needs documented as to the sources used for model.  If source is based on work of researchers at Public Universities or use reverse engineered patented technology.  The documentation helps when other company patents similar technology and puts first company out of business with a Patent suite.       

 

The value of program like this could be extended by including ear tag information on each cow which allow better documentation of the pharma given to each animal.   Some farmers like the tag program but the packing houses do not. 

Hopefully a program like this could be used for public good and allow inspection of data by researchers.

 

One example of good technology on dairy cows.  The modern milker machine senses exactly when the cow milked out--over milking makes for an unhappy cow.  When milk production decreased in an area, researchers found that a modern milker when powered by poorly grounded mains supply would shock the cow. :classic_dry:

        

 

   

Edited by Pat Foley
add line.

Share this post


Link to post

👍

 

Remember: sometimes it is required to load the complete project, including DPR, DFM...then the ZIP format is your choice. :classic_cool:

 

Background:  if the external server is closed, the thread here is incomplete. :classic_huh:

Share this post


Link to post
1 hour ago, haentschman said:

Attach files HERE...not at a external server

I like online more so that I don't have to download stuff which then needs to be deleted... too much excess actions. These files are for evaluation purposes anyway.

 

As for the code: it's quite poor. Not the most awful one I've seen but something like I wrote when I was student. IMHO it first needs careful refactoring (no serious skills really, just accuracy and some knowledge of what's right and wrong).

Edited by Fr0sT.Brutal

Share this post


Link to post

I can't move on with my problem. So I adjusted one unit as part of the relaxation.

  1. I used automatic text formatting
  2. I inserted blank lines to increase readability
  3. I did not deal with unnecessary and missing begin-end pairs
  4. I personally use a 120-character line. I didn't apply it here. In Word, it fits on one side.  

The number of rows has increased, which I do not consider to be a mistake.

rumengut.pas

Share this post


Link to post
procedure TEventBoss.moveMouse(AC: Tcontrol);
const
  gravity =-9.8;//gravity
  wind = 17;   //West wind derecho force
  buoyancy = 62; //lbs floated in firken of displaced snowmelt
  buoyancySteamAir = 18/28; //MW of water/Mw of Air assume water returns as hailStones; //:(
  XYtolerance = 6;
var
  eX, //MouseXError
  eY, X, Y: integer;// nativeInt;
  vtX, vtY: integer;//terminal velocity
  newMousePT: TPoint;
  MainF : TControl;

begin
  X := AC.CLientOrigin.X + AC.Width div 2;
  Y := AC.CLientOrigin.Y + AC.Height div 2;

  eX := round(0.4 * (x - mouse.CursorPos.X + wind));
  eY := round(0.4 * (y - mouse.cursorPos.y - gravity));
  vtX := 12 + sign(eX) * wind div 2;
  vtY := 8 + sign(eY) * trunc(-Gravity) div 2;
  eX := Min (abs (eX),vtX) * sign(eX);
  eY := Min (abs (eY),vtY) * sign(eY);
  newMousePT.X := mouse.CursorPos.x + eX;
  newMousePT.Y := Mouse.CursorPos.y + eY;
  mouse.CursorPos := newMousePT;

  If (abs(eX) + abs(eY)) < XYtolerance then // MN for XYtolerance;
    moveMousetoInstance := nil;

  if AC.parent = nil then
    MainF := AC
    else if AC.Parent.Parent = nil then
      MainF := AC.Parent
      else
        MainF := AC.Parent.Parent;

  // following adjusts for the ocean domain
  // form floats up after "submerging" into water
  if newMousePT.Y > Screen.Height - buoyancy * 3 then
  MainF.top := MainF.Top - abs(eY);
  // following adjusts for the troposphere domain
  // form floats on denser air
  if newMousePT.Y < Screen.DesktopTop + round(buoyancySteamAir * 350) then
  MainF.top := MainF.Top + abs(eY);
  // form in left ditch pull it out a little each timer event.
  if newMousePT.X < 0 then
    MainF.Left := MainF.Left + abs(eX);
  if newMousePT.X > screen.width then
    MainF.Left := MainF.Left - abs(eX);
end;

This code example shows code that moves the mouse to a component on a form when it is opened.  When Y is small the form floats

in air domain.  When Y is big form floats in water domain

 

The example shows how the errors eX and wY, caused by the influence of wind and gravity*, is solved by integrating the error correction

over time into mouse path as it moves towards the control.  When movemousetoInstance is nil the timer skips the call to movemouse

in the timer routine. 

 

Chemical tensions could be modeled in your rumen domain.   

Further setting initial conditions and saved model state would be good allowing the model converge quickly.  

 

 

I thinking about the cruft, would the pH be locally lower with carbonic acid working on what's floating or is it floated by CO2 offgas? 

 

  

 

      

* Imaginary use of green energy to power the mouse.

 

 

 

Share this post


Link to post

For algorithms to be maintainable and testable, they need to be separated from the UI.

The UI can deliver inputs, but the math/logic needs to be black boxed seen from a UI perspective.

  • Like 1

Share this post


Link to post
6 hours ago, Lars Fosdal said:

For algorithms to be maintainable and testable, they need to be separated from the UI.

The UI can deliver inputs, but the math/logic needs to be black boxed seen from a UI perspective.

The difference between a mathematician and an engineer is the engineer uses pictures.  We use some very abstract concepts to solve efforts and flows using first principles and plot to chart when needed.    

 

Process control scheme for brewery or a sewage plant might be source of model to use.  The rumen reticulated* could be reduced to flash tank, holding tank, settling tank with vents and reflux. The process variables are moved between tanks and then computed.    The variables are made persistent by list of pointers loaded at runtime to use with procedures and save state and used in UI.  

 

The ash or minerals passing through helps decide if the stool is sinker or floater.:classic_dry:

 

*networked

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

×