Corion / app-shadertoy

Native shader viewer like https://www.shadertoy.com
Artistic License 2.0
17 stars 2 forks source link

perltidy? #8

Open wchristian opened 7 years ago

wchristian commented 7 years ago

The code is in kind of an ad-hoc style. Any chance of adding a .perltidyrc file to be used consistently?

Corion commented 7 years ago

I'm not sure if Perltidy supports the new signatures that I'm using. Also, I'm not sure where my code is particularly ad-hoc :-) If Perltidy works on Windows, I'll try installing it, but I'd prefer not to spend hours trying to configure it in a way that it doesn't mess up all code.

I'm planning to look at moving OpenGL::Glew into a local copy of the OpenGL / pogl distribution this weekend, and that code certainly should follow the style of OpenGL when it is merged. I'm not sure if Perltidy can handle some files but not others.

wchristian commented 7 years ago

Looking at app-shadertoy.pl it's not just the formatting of it, but also the kinda eclectic structuring of it that makes it hard to read for me (wild mix of pod, comments, module level code, functions, etc.). Additionally there's a mix of spaces and tabs.

In any case, i still think it'd be valuable to have. I added a basic .perltidyrc file and ran all the things through it so you can see what happens: https://github.com/wchristian/app-shadertoy/tree/tidy (careful looking at the commit in browser, it's kinda big)

It handles the signatures fine.

As for perltidy and windows: I use Komodo IDE on windows and have perltidy and komodo configured so i can hit ctrl+e and it'll tidy the open file or selected block of text. Has been working great for years. :)

Corion commented 7 years ago

I like how Perltidy will change and fix the mixture of tabs and spaces - this is due to me switching editors recently and my new settings haven't propagated through all the code. There should be no tabs left anywhere.

Unfortunately, the rest of your settings seem pretty unacceptable to me, or require lots of fiddling with .perltidyrc which I would rather not spend time on:

my @vertices = ( -1.0, -1.0,   1.0, -1.0,    -1.0,  1.0,    
                  1.0, -1.0,   1.0,  1.0,    -1.0,  1.0
               );

gets converted to

my @vertices
    = (-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0);

losing the "pairs" information.

my $config = {
    grab => 0,
};

gets converted to

my $config = {grab => 0,};

making it hard to add more config items later.

I'm not interested in fighting another tool just to prevent it from making understandable but stupid mistakes all the time. I know that the above is likely inconsistent with other syntactically identical situations but as there is information that is conveyed not in the syntax but in the whitespace, the forced unification through Perltidy is not worth it to me.

But there certainly are sections that benefit from the unification. I guess that running the code through Perltidy and cleaning the relevant parts by importing them into git manually is sensible, but not as an ongoing part of the process.

wchristian commented 7 years ago

Easily fixed by adding comment markers. Give me a sec.

wchristian commented 7 years ago

Please consider: https://github.com/wchristian/app-shadertoy/commit/587c5257ac6265023343445a9e69b0e31f28bfc0

wchristian commented 7 years ago

If you're familiar enough with Perltidy to know which knobs to twiddle, I'll compile a list of the things I don't like and I'll get back.

Please do, i'd happily do that, and i already know the setting needed for the signatures one. :)

But I'm already not that keen on adding special markers for "leave this untouched".

I can understand that, but consider: In the case of the vertices a comment explaining what is what and why it's like that would be appropiate, and in the case of the config, the marker can probably go away once you have more than one config pair. Some of the things are also that way because i configured a very long line length.

Generally once you're past the initial settling in bit, tidy is really smooth flying, especially if you have someone familiar on hand. :)

Corion commented 7 years ago

I'm writing these down so that I don't forget. If there are easy fixes for them, tell me, but I'm not promising that these are all things that annoy me with the perltidy settings ;)

Things that break using Perltidy for the moment for me:

The following makes Perl::Tidy stop parsing:

sub foo( $options={} ) {
}

This is especially annoying as for OpenGL, there usually are flat lists of floats passed around and the whitespace there has semantic meaning. There is the "comment at first line" workaround.

gets inlined to

My::Class->new( some => 'argument', );

which is not what I want, because likely I'll add more arguments later. I understand that this is hard to disambiguate for Perl::Tidy from other function calls that might be safely moved onto a single line.