Recent

Author Topic: Format Code before save automatically  (Read 2560 times)

aag031

  • Newbie
  • Posts: 4
Format Code before save automatically
« on: February 22, 2022, 10:14:22 am »
Dear All
Is there possibility formatting code  automatically before saving?

From other hands

Is there possibility when user clicks save button code is formatted then saved
I did not find this possibility in options configuration.
I've started to use Lazarus recently, may be I missed something


WBR
Alexander

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
Re: Format Code before save automatically
« Reply #1 on: February 22, 2022, 10:35:07 am »
Seems no 'on save'. But you can call IDE menu "Souce / Jedi code format" menu to run it.

Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: Format Code before save automatically
« Reply #2 on: February 22, 2022, 10:43:27 am »
I have no idea why someone would need such a feature.....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Sniper

  • New Member
  • *
  • Posts: 39
Re: Format Code before save automatically
« Reply #3 on: May 06, 2022, 09:49:09 am »
I have no idea why someone would need such a feature.....

If you works in a team then you definitely have to follow for style guides. :)

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Format Code before save automatically
« Reply #4 on: May 06, 2022, 03:49:49 pm »
I have no idea why someone would need such a feature.....
If you works in a team then you definitely have to follow for style guides. :)
But then you have it to use _before_ save. Because ia team you use normal a Sourcecontrol tool and it is not good, automatic styles are automatic added on code. It confuses the diffs. It is hard enough with lineendings on the the three platforms and GIT.
regards
Andreas

Sniper

  • New Member
  • *
  • Posts: 39
Re: Format Code before save automatically
« Reply #5 on: May 06, 2022, 05:22:53 pm »
I have no idea why someone would need such a feature.....
If you works in a team then you definitely have to follow for style guides. :)
But then you have it to use _before_ save. Because ia team you use normal a Sourcecontrol tool and it is not good, automatic styles are automatic added on code. It confuses the diffs. It is hard enough with lineendings on the the three platforms and GIT.
Git has an option how to deal with line endings.

Ok, Python, Go has numerous utils to lint (mypy, pylint.. ) and format (gofmt..) the code before save. This is a cool feature for development in big teams isnt it? As 2022 language Freepascal must have this type of "sugar" too. Am I wrong?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: Format Code before save automatically
« Reply #6 on: May 06, 2022, 05:42:43 pm »
Automated formatting in pascal is not an new phenomenon, and also the difference in opinion is quite an old fight, I can remember it already having it in the early 2000s. It is by no means something modern.

In Lazarus circles it is not very popular, and in Delphi circles only slightly more. Usually in such cases formatters are run in the post commit hook of the VCS.

I never cared much for it. The benefits are doubtful, and only triggers eternal discussion about what should be the right style right down to the extremely trivial. All that time micromanaging  is better spent elsewhere.
« Last Edit: May 06, 2022, 06:32:51 pm by marcov »

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: Format Code before save automatically
« Reply #7 on: May 06, 2022, 09:43:27 pm »
This is no new discussion about sugar (its more salt). I know this dicussion back to the M80/L80/Cref80 times on CP/M. And later TP on this platform. 

Yes you are wrong. I is the same old discussion like other.
regards
Andreas

440bx

  • Hero Member
  • *****
  • Posts: 4064
Re: Format Code before save automatically
« Reply #8 on: May 06, 2022, 10:13:24 pm »
This is a cool feature for development in big teams isnt it? As 2022 language Freepascal must have this type of "sugar" too. Am I wrong?
I strongly believe in the value of properly formatted code.  When properly formatted, the code is easier to understand and easier to maintain.

That said, as others above have already mentioned, code formatting seems to vary significantly from programmer to programmer and, opinions about what the format should be, even more.

My personal opinion is that a programmer should format the code as he/she is programming.  That should be instinctive and automatic thus making code formatters utilities of questionable value because, if the programmer can't figure out how to format code or not take the minimal amount of time it takes to format code then, that's quite likely not code I want to read (formatted or otherwise.)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Format Code before save automatically
« Reply #9 on: May 09, 2022, 01:38:38 pm »
Ok, Python, Go has numerous utils to lint (mypy, pylint.. ) and format (gofmt..) the code before save. This is a cool feature for development in big teams isnt it? As 2022 language Freepascal must have this type of "sugar" too. Am I wrong?

Lazarus has the Jedi Code Formatter and there's also the command line utility ptop. I'm sure someone would be able to hook them up to the IDE in a way they can be triggered upon safe (JCF can already be triggered with an explicit key sequence if installed). Or at least the latter could be used as part of a commit hook or whatever. So everything that's needed is there (though both components might struggle with some language features).

 

TinyPortal © 2005-2018