Good Haskell Style

View: New views
15 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 - 3 | Next >

Re: Good Haskell Style

by Benjamin Franksen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Fairbairn wrote:

> David Roundy <droundy@...> writes:
>> Trailing white space doesn't particularly hurt, except if you're using
>> version control, in which case any removal of white space is liable to
>> conflict with actual coding changes, so it's better to have a policy that
>> it shouldn't be included.
>
> This is surely an issue with either the language definition
> or the version control system.  In general, we ought to aim
> for a state of affairs where every requirement we make is
> mechannically checked. In this particular case, I'd say that
> the version control system ought to be more syntactically
> aware when looking for differences¹, for example by removing
> all trailing space before doing comparisons (and making sure
> that anything extracted from the repo has none).
>
>>  I've certainly never heard of a scenario in which
>> trailing white space is beneficial.
>
> Neither have I, but since it's invisible, asking that it not
> be there without providing automatic mechanical assistance
> is to add a tedious burden.

sed -e 's/[ \t]+$//'

Cheers
Ben

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Jon Fairbairn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Benjamin Franksen <benjamin.franksen@...> writes:

> Jon Fairbairn wrote:
> > David Roundy <droundy@...> writes:
> >>  I've certainly never heard of a scenario in which
> >> trailing white space is beneficial.
> >
> > Neither have I, but since it's invisible, asking that it not
> > be there without providing automatic mechanical assistance
> > is to add a tedious burden.
>
> sed -e 's/[ \t]+$//'

Not the whole story, surely; you must want me to do
something like create sort-it:

#!/bin/bash
find /home/jf -name \*.hs -o -name \*.lhs | xargs -IX sed -i.bak -e 's/[ \t]+$//' X

and put it in a my crontab to run once a day? Otherwise it's
not automatic. Only, strangely enough, what you wrote
doesn't work (s/-e/-r/).

--
Jón Fairbairn                                 Jon.Fairbairn@...


_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Jon Fairbairn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Roundy <droundy@...> writes:

> On Thu, Aug 02, 2007 at 11:48:37AM +0100, Jon Fairbairn wrote:
> > [1] this isn't the only place where a version control system
> > that understood more of the language would be useful: for
> > example, rather than having to specify a regexp, I'd like
> > darcs replace to pick one (from a configuration file?)
> > depending on language.
>
> This latter bit is pretty easily added, but I doubt many people have
> repositories in which they use darcs replace often on multiple languages,
> so it seems like it ought to be pretty low-priority.

I wasn't particularly thinking of multiple languages.  The
default is wrong for Haskell, for example, so I have to put
something in _darcs/prefs/defaults. Surely it would be
better to do that once and for all?

--
Jón Fairbairn                                 Jon.Fairbairn@...


_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Benjamin Franksen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Fairbairn wrote:

> Benjamin Franksen <benjamin.franksen@...> writes:
>> Jon Fairbairn wrote:
>> > David Roundy <droundy@...> writes:
>> >>  I've certainly never heard of a scenario in which
>> >> trailing white space is beneficial.
>> >
>> > Neither have I, but since it's invisible, asking that it not
>> > be there without providing automatic mechanical assistance
>> > is to add a tedious burden.
>>
>> sed -e 's/[ \t]+$//'
>
> Not the whole story, surely;

No, of course not.

> you must want me to do

I don't want you to do anything at all. I merely wanted to illustrate that
getting rid of trailing whitespace is easily automated. Well, let's say
half-automated: you still need to push the button.

> something like create sort-it:
>
> #!/bin/bash
> find /home/jf -name \*.hs -o -name \*.lhs | xargs -IX sed -i.bak -e 's/[
\t]+$//' X
>
> and put it in a my crontab to run once a day? Otherwise it's
> not automatic.

No crontab entry needed here (wouldn't help, by the way, since you probably
want to record on the same day you wrote something). Also not necessary to
recurse over whole home directory. It needs to be done only right before
darcs-record-ing changes and only for the standard libraries. As has been
noted by someone else, darcs even helps you by highlighting trailing
whitespace in hunks, in case you forgot to run your script over the source
files.

I agree that a darcs prehook (if they existed) would be an even nicer
solution.

> Only, strangely enough, what you wrote
> doesn't work (s/-e/-r/).

Sorry, I didn't test the code. Forgot to add the usual disclaimer... ;-)

(Always bugs me that sed and grep have these half-regexes as default.)

Cheers
Ben

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Bugzilla from droundy@darcs.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Aug 02, 2007 at 06:52:01PM -0700, Ashley Yakeley wrote:

> Ian Lynagh wrote:
>
> >* Don't leave trailing white space in your code
> >* Don't use tabs
> >* Aim to keep lines under 80 characters
> >* Use the CamelCase variable naming convention
> >* Don't use explicit braces and semicolons
>
> "by giving a parse error if we break any of its rules" -- well, you
> hope, right?
>
> My own preferences:
...
> * Use one tab to indent each level. Display them at 4 space boundaries.

But this means that your code will have the possibility of layout bugs that
not visible to the programmer, since according to the report a tab
corresponds to eight spaces.  Sounds like the worst of all possible
worlds.
--
David Roundy
Department of Physics
Oregon State University
_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Ashley Yakeley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Roundy wrote:
>> * Use one tab to indent each level. Display them at 4 space boundaries.
>
> But this means that your code will have the possibility of layout bugs that
> not visible to the programmer, since according to the report a tab
> corresponds to eight spaces.  Sounds like the worst of all possible
> worlds.

No layout bugs:

* Use explicit braces and semicolons. Use "Allman" style.

--
Ashley Yakeley

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Isaac Dupree :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ashley Yakeley wrote:
> No layout bugs:
>
> * Use explicit braces and semicolons. Use "Allman" style.
>

I'm sure you could come up with a little better convention than this,
but here you go (or does "Allman style" refer to something particular?
if so, what?) :

module Foo (bar, Baz(..)) where {
import Prelude
;
bar :: Ordering -> Bool
;
bar x = case x of { LT -> True; _ -> False }
;
data Baz a where {
     Oops :: Num a => Bool -> IO a -> Baz a
     ;
     Fine :: Baz ()
    }
}

Oh by the way Ashley Y, have you seen my comment about the HaskellWiki
at the end of http://haskell.org/haskellwiki/Talk:Haskell  (I know this
is off topic but I don't want to be spam-filtered or missed again!)

Isaac
_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Isaac Dupree :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Fairbairn wrote:

> David Roundy <droundy@...> writes:
>
>> On Thu, Aug 02, 2007 at 11:48:37AM +0100, Jon Fairbairn wrote:
>>> [1] this isn't the only place where a version control system
>>> that understood more of the language would be useful: for
>>> example, rather than having to specify a regexp, I'd like
>>> darcs replace to pick one (from a configuration file?)
>>> depending on language.
>> This latter bit is pretty easily added, but I doubt many people have
>> repositories in which they use darcs replace often on multiple languages,
>> so it seems like it ought to be pretty low-priority.
>
> I wasn't particularly thinking of multiple languages.  The
> default is wrong for Haskell, for example, so I have to put
> something in _darcs/prefs/defaults.

And it's not there when darcs-getting a repository of Haskell code,
which is rather irritating since contributed patches SHOULD use the
appropriate convention (for patch commutation as well as correctness of
replacement).  Although, I'm not sure how this can be fixed in the darcs
model of looking at things?

Isaac
_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Ashley Yakeley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Isaac Dupree wrote:
>> * Use explicit braces and semicolons. Use "Allman" style.
>>
>
> I'm sure you could come up with a little better convention than this,
> but here you go (or does "Allman style" refer to something particular?
> if so, what?) :

<http://en.wikipedia.org/wiki/Indent_style#Allman_style>

module Foo (bar, Baz(..)) where
{
     import Prelude;

     bar :: Ordering -> Bool;
     bar x = case x of
     {
         LT -> True;
         _ -> False;
     };

     data Baz a where
     {
         Oops :: Num a => Bool -> IO a -> Baz a;
         Fine :: Baz ();
     }
}

(but I've used spaces here)

> Oh by the way Ashley Y, have you seen my comment about the HaskellWiki
> at the end of http://haskell.org/haskellwiki/Talk:Haskell  (I know this
> is off topic but I don't want to be spam-filtered or missed again!)

OK, I'll fix it...

--
Ashley Yakeley

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Jon Fairbairn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Benjamin Franksen <benjamin.franksen@...> writes:

> I don't want you to do anything at all. I merely wanted to illustrate that
> getting rid of trailing whitespace is easily automated. Well, let's say
> half-automated: you still need to push the button.

[...]

> No crontab entry needed here

The code was ironic ;-)

> I agree that a darcs prehook (if they existed) would be an even nicer
> solution.

Quite.  My point that computers are /for/ making things
automatic.  If they can remember to press the button, why
should I have to?  Or, less petulantly, being human I will
inevitably forget sometimes (resulting in problems), where
the machine wouldn't.

--
Jón Fairbairn                                 Jon.Fairbairn@...


_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Isaac Dupree :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ashley Yakeley wrote:
> Isaac Dupree wrote:
>>> * Use explicit braces and semicolons. Use "Allman" style.
>>>
>>
>> I'm sure you could come up with a little better convention than this,
>> but here you go (or does "Allman style" refer to something particular?
>> if so, what?) :
>
> <http://en.wikipedia.org/wiki/Indent_style#Allman_style>

Okay, luckily Haskell generally allows extra semicolons, so that works
:-)  (in fact I believe the extra semicolons being allowed was important
for flexible _layout_ rules, for use in combination with explicit
semicolons, and thereby helped make sure that non-layout syntax was nice
and flexible too!)

Isaac
_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Nils Anders Danielsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 02 Aug 2007, Thomas Schilling <nominolo@...> wrote:

> (defun delete-trailing-space ()

FYI: There is a standard function delete-trailing-whitespace which you
could use.

>     (add-hook 'write-file-hooks 'delete-trailing-space)

And write-contents-hooks may be more appropriate.

--
/NAD

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Thomas Schilling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 6 aug 2007, at 17.12, Nils Anders Danielsson wrote:

> On Thu, 02 Aug 2007, Thomas Schilling <nominolo@...> wrote:
>
>> (defun delete-trailing-space ()

Yes, thanks.  That was also pointed out by Chris, in this thread.

> FYI: There is a standard function delete-trailing-whitespace which you
> could use.
>
>>     (add-hook 'write-file-hooks 'delete-trailing-space)
>
> And write-contents-hooks may be more appropriate.

Thanks, I take a look.  As Simon Marlow mentioned, this however does  
not solve our problem.  I just fell into that trap myself, because I  
accidentally kept that hook on a file I was working on, and had a  
very hard time filtering out the actual changes when I recorded my  
darcs patch.  Hooking this feature in with highlight-changes-mode  
might give us a way to find out which lines were actually modified,  
but even then the best way to integrate this would be with darcs or  
some darcs mode.  I use darcsum.el, which works rather well, but is  
far from perfect.

I take a look.

Thanks,
/ Thomas
_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Nils Anders Danielsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 06 Aug 2007, Thomas Schilling <nominolo@...> wrote:

> As Simon Marlow mentioned, this however does not solve our problem.

No, it does not solve Simon's problem, but it is a quick and simple
solution which works well for files that are created and edited only
by you. Furthermore a little white space in some patches may not be
much of a problem.

--
/NAD

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries

Re: Good Haskell Style

by Johan Bockgård :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Simon Marlow <simonmarhaskell@...> writes:

> While we're on emacs... I know I can colour trailing whitespace
> differently, but that's just annoying.

You could use something more discreet, like colored underlines.

> What I want is: on lines that I edit, remove the trailing whitespace
> (and if I undo the edit, put the whitespace back too). Is there
> something that does that?

    ;; Difficulties are that a) in general changes doesn't necessarily
    ;; happen at the location of point, and OTOH b) commands can
    ;; temporarily move point behind the scenes, but c) we don't want
    ;; characters do disappear under our feet (point) . Try to do
    ;; something sensible.
    (defun line-delete-trailing-whitespace (beg end len)
      (unless (or (eolp) undo-in-progress)
        (save-excursion
          (end-of-line)
          (delete-char (- (skip-chars-backward " \t" end))))))

    ;; Buffer local, use a mode hook
    (add-hook 'after-change-functions 'line-delete-trailing-whitespace nil t)

    ;; To see what's going on
    (setq show-trailing-whitespace t)

--
Johan Bockgård

_______________________________________________
Libraries mailing list
Libraries@...
http://www.haskell.org/mailman/listinfo/libraries
< Prev | 1 - 2 - 3 | Next >