Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Style guideline and code beautification #287

Closed
Mayriad opened this issue Apr 26, 2020 · 2 comments
Closed

[Suggestion] Style guideline and code beautification #287

Mayriad opened this issue Apr 26, 2020 · 2 comments

Comments

@Mayriad
Copy link
Contributor

Mayriad commented Apr 26, 2020

I am going to get fussy now, but this is of course not a real problem that needs to be fixed.

I have only read and worked on a tiny proportion of the code, but the existing coding style I have seen so far is very messy and made it difficult for me to comply. I will list some problems below; all examples are taken from EHentai.pm:

  • Spaces inside brackets, which is uncommon and also not consistently applied:
if ( $gID eq "" ) {
...
if ($hashdata{tags} ne "") {
  • Visual indentation, which cannot be consistently applied anyway:
my ( $title, $tags, $thumbhash, $defaultlanguage, $ua, $domain, $usethumbs) = @_;
my $logger = get_logger( "E-Hentai", "plugins" );
my $URL    = "";
  • Inconsistent indentation:
    } else {
        # Craft URL for Text Search on EH if there's no user argument
        ( $gID, $gToken ) =
          &lookup_gallery( $lrr_info->{archive_title}, $lrr_info->{existing_tags}, 
                           $lrr_info->{thumbnail_hash}, $lang, $lrr_info->{user_agent}, $domain, $usethumbs);
  • Inconsistent variable naming:
my $lrr_info = shift; # snake_case
my ($lang, $savetitle, $usethumbs, $enablepanda) = @_; # flatcase
...
my $gID    = ""; # camelCase
  • Undescriptive variable names:
my $rep = $ua->post(
  • Lack of code width limit e.g., line 29 in EHentai.pm has 1887 characters.
  • Mixed use of ' and " that cannot be justified by functional differences.
  • Trailing spaces that should be trimmed.

Beautifying existing code is obviously not productive, so I am not sure if anything can be done about it ¯\_(ツ)_/¯. Feel free to dismiss and close this issue.

@Difegue
Copy link
Owner

Difegue commented Apr 27, 2020

Been a while since I last did a global PerlTidy pass, so this should alleviate most of your problems.
I've also included the .rc file matching the rules I use at the moment (which did change a bit from when I started 5 years ago...), which gives you a baseline to go along.

If you plan on contributing further, you can use this .rc with a perltidy install and a formatter. (I use https://github.com/kak-tus/perltidy-more for vscode)

Some extras:

  • Code width limit is stupid for long strings and comments (ie the base64 pngs in plugin metadata), which is perltidy's default behavior.
  • The visual indentation is made by perltidy but I actually really like it, so I leave it in and try to repro it whenever it makes sense.
  • The codebase does have issues with variable naming -- perl packages usually go for snakecase buuut short variables are ok in flatcase (extract from perlstyle)
    image I usually go with camelcase in other languages but I feel it's not a good fit here.
  • ''s should only be used for escaping " easily and vice-versa but I don't really care about that one. 😐

@Difegue
Copy link
Owner

Difegue commented May 1, 2020

I've added the above paragraph to the documentation as well -- Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants