FAQ
Hello,

Just throwing out an idea to see if others might find it useful. I
frequently find myself writing two separate versions of
system-specific code; one for Windows and one for POSIX systems. The
way I typically achieve is by naming the POSIX version xyz.go and the
windows version xyz_windows.go. The POSIX version has to have the
following build constraint in the file:

// +build !windows

I think it would be better if there was a special '_other' suffix that
could be added to files. A file named xyz_other.go is compiled only if
no other xyz_*.go files are applicable to the current environment.

This makes the intention clear, because with xyz.go and xyz_windows.go
you can't immediately tell if the latter is adding some extra code on
Windows or if the two are mutually exclusive. It also simplifies the
process for adding new system- or architecture-specific code. If, at
some later point, I decide that FreeBSD needs special handling, I can
add xyz_freebsd.go without having to modify the +build line in xyz.go.

Thoughts?

- Max

--

Search Discussions

  • David Symonds at Oct 19, 2012 at 12:04 am
    I don't think it's worth the added complexity. Even if you have a
    dozen arch/OS/environment-specific variations, you still only have to
    edit two files to add a new variation: the new file being added, and
    the generic one (to add a single line or a new clause to its existing
    // +build comment).

    --
  • Brainman at Oct 19, 2012 at 12:10 am

    On Thursday, 18 October 2012 23:15:46 UTC+11, Maxim Khitrov wrote:

    ... Thoughts?
    It sounds good. But I am not sure.

    Do not forget about negatives:

    - packages with source file like abc_other.go will suddenly stop building;
    - new more complex rules for go source file names;
    - ... maybe something else, I do not know ...

    You have to consider, if the benefits are worth it. Perhaps, what you could
    do is look at go source and see if your suggestion will simplify some
    packages. I am not convinced.

    Alex

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 18, '12 at 12:38p
activeOct 19, '12 at 12:10a
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase