FBeauty.bas, a Geany custom command for code beautyfying

User projects written in or related to FreeBASIC.
TJF
Posts: 3355
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby TJF » Sep 16, 2018 11:44

badidea wrote:Trying to convert the code into a class, so I can use it more easy in some code of mine...

You can set up three key-startet Geany commands. And several more startet by mouse activity. Which other features do you use, so that you are short of free command slots?

I use
    <crtl>-1: FBeauty -> fix character cases
    <crtl>-2: fbdoc -> generate templates for documentation (+ translate FB code to C code)
    <crtl>-1: h_2_bi -> translate C code to FB code
Beautifying is an important step in my development. I first code in lower case letters. Then I test the code and when all checked, I change the code to upper case only. That way I can easy differentiate between unreliable and already finished code.

badidea wrote:Haven't checked to "-i" option yet.
What do you think of the conversion?
Would be cool to include an indent fixer. Not sure how complex that is.
It's open source, so you're free to convert the code to whatever you want. And convert it again after the next update.

Transforming keyword letter cases and auto indenting have totally different code parsing requirements. Auto indentation needs more information than the FBeauty parser can serve.

From my point of view auto-indentation is a bad idea. It's for people who always do what their teachers say. I often use custom indentation to make code more easy to understand. For example this code fragment from libpruio example pwm_cap

Code: Select all

WITH *io
  DO
    IF .Errr                     THEN ?"NEW failed: " & *.Errr : EXIT DO

    IF .Cap->config(P_IN, 2.) THEN _ '               configure input pin
                ?"failed setting input @P_IN (" & *.Errr & ")" : EXIT DO

    DIM AS Float_t _
        f1 _ '*< Variable for calculated frequency.
      , d1 _ '*< Variable for calculated duty cycle.
      , f0 = 31250 _ '*< The required frequency.
      , d0 = .5      '*< The required duty cycle.
    IF .Pwm->setValue(P_OUT, f0, d0) THEN _
              ?"failed setting output @P_OUT (" & *.Errr & ")" : EXIT DO

    IF .config(1, 2) THEN _ '                upload configuration to PRU
                                   ?"config failed: " & *.Errr : EXIT DO
...
The normal executing is at the left edge from top to bottom, and exception handling is at the right edge (EXIT DO). Regardless how long the error message is, it always ends at the 72's column, and is more easy to find that way. Auto-indentation will destroy that advanced code format.
badidea
Posts: 1004
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby badidea » Sep 16, 2018 16:02

TJF wrote:Which other features do you use, so that you are short of free command slots?
None :-)

I don't mind ugly code (up to a certain point) myself, but when publishing/posting I like it to be nicer.
Like my house. I don't mind if it is a mess. But when people come visit, I clean up a bit.

I don't do comment alignment normally, takes too much time every time I change the code.
Just right after the code and the line above
Also 80 column mark I often ignore. With today's widescreens and GUI based OS, its not so important.
I don't even known where the 72 width comes from. I think I read it once, but forgot again.

You are right about auto-indent. But sometimes one encounters code where everything is messed up. Tabs and spaces. In those cases auto-indent would probably make it more readable.
TJF
Posts: 3355
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby TJF » Sep 16, 2018 16:37

Do you know that Geany can auto-indent for you? When I type 'if' and the <tab> key, Geany creates

Code: Select all

IF  THEN
 
ELSE
 
END IF
and places the cursor after 'IF', where I can edit the conditional statement. <shift>-<tab> jumps to the next position to place custom code (start of line under THEN, indentation 2 spaces; next jump is to start of line under ELSE, indentation 2 spaces). The feature is called 'snippets'. I made similar snippets for major keywords like 'for', 'do'. 'whi' (WHILE). 'def' (#DEFINE), fun (#FUNCTION), ...

All indentations are prepared by Geany. When I don't need the ELSE statement, it's easy to remove. Or I can duplicate the line and append 'IF' for an 'ELSEIF'.
badidea
Posts: 1004
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby badidea » Sep 16, 2018 19:03

I did not know that Geany do code completion. It is not doing that here, I'll look into it.
I do know other other stuff like ctrl+d, ctrl+k, ctrl+e, ctrl+shift+m, tab & shift-tab with code block.
Boris the Old
Posts: 118
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby Boris the Old » Oct 07, 2018 1:25

badidea wrote:
TJF wrote:....Also 80 column mark I often ignore. With today's wide screens and GUI based OS, its not so important. I don't even known where the 72 width comes from. I think I read it once, but forgot again.


The 80 columns is from punched cards. Back in the '50s and '60s, each programming language had its own coding sheet layout. For example, languages such as Autocoder and SPS (Symbolic Programming System) used columns 1 to 3 for sequence numbers, whereas RPG (Report Program Generator) used the last 3 columns. The original COBOL used columns 1 to 6 for sequence numbers, and columns 73 to 80 for the program name. Now, COBOL is free format, with no column restrictions (it also has all the modern gimmicks such as OOP). Column 72 was the last column for code. Beyond that the data was ignored by the compiler.

Having pre-assigned columns, for sequence numbers and program names, was insurance against the inevitable - dropped card decks. A few passes through a card sorter would put everything back in sequence. I once had a customer who, for security reasons, kept all his card decks in the trunk of his car. Unfortunately, he didn't anticipate being rear-ended on the Gardiner Express Way in Toronto. Apparently, the event was quite spectacular. But sadly, a significant number of cards were lost to the depths of Lake Ontario.

By the way, I've used all the languages named above. :)

Rod
TJF
Posts: 3355
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby TJF » Oct 07, 2018 8:54

Thanks Boris, for the information!

In the 15. century the German blacksmith Johannes Gensfleisch (named Gutenberg) invented the printing technology, which gets used and improved over the years. Scientist found out that the human eye can easy find the start of the next line up to a line width of 72 characters (including white spaces). In case of longer lines the risk of re-reading the same line or skipping a line increases a lot. That's why the text in a newspaper doesn't use the full page width, instead it's formated in columns.

Later, the punch card designers take over that design.
Imortis
Posts: 1576
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: FBeauty.bas, a Geany custom command for code beautyfying

Postby Imortis » Oct 08, 2018 19:01

Boris the Old wrote:... RPG (Report Program Generator) ... COBOL ...
By the way, I've used all the languages named above. :)


I used RPGIV in college as well as COBOL. I still have a pad of those Layout sheets somewhere in a closet. That was wild stuff. Thanks for bringing back those memories!

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest