Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

optimal width of line of code

Name: Anonymous 2011-05-07 15:11

Why people want to keep those tight limits of width of line of code? What is more readable?

bar = baz().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo()

or:

[pre]a = baz().foo().foo().foo().foo().foo().foo()
b = a.foo().foo().foo().foo().foo().foo().foo()
bar = b.foo().foo().foo().foo().foo().foo()[/pre]

For me first option is much better, because i don't heave to remember, what a, b means.

Name: Anonymous 2011-05-07 15:26

bar = baz().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo()
    .foo().foo().foo().foo().foo().foo().foo().foo().foo()

Name: Anonymous 2011-05-07 15:33

cool hyperbole bro
your example is rubbish, you will never find such a long operator chain in any code but trollcode or obfuscated shit.

Name: Anonymous 2011-05-07 15:35

Where 'COUNT' is the number of times the loop iterates ...
int i = 0, COUNT = ##;
bar = baz();
while(i < COUNT) {
   bar = bar.foo();
   ++i;
}

Now, was that so hard?  The type of bar, if that's even applicable, is left as a requirement for the user to define.

Name: Anonymous 2011-05-07 15:43

>>1
This is more readable:
(((int->church 19) (λ (x) (foo x))) (bar))

Name: Anonymous 2011-05-07 15:43

>>5
I MENA (((int->church 19) foo) (bar))

Name: Anonymous 2011-05-07 15:46

>>4

int i;
for(i=0,bar=baz();i++<COUNT;bar.=foo());

OMG OPTIMIZED

Name: Anonymous 2011-05-07 15:51

It was general question and code, that I posted was only example. Sure, that if there would be only bar() methods it should be written like mentioned. But what about more realistic example:

bar = object.perform_some_action_A().perform_some_action_B().perform_some_action_C()

Most people say, that there should be temporary variables to make line shorter and more readable. Well, maybe back in time, when low resolution CRT monitors were used it was OK, but now? I also don't agree, that this indicate, that code is wrongly designed, because, as I mentioned it actually increased density and readability.

Name: Anonymous 2011-05-07 15:59

bar = object.perform_some_action_A().perform_some_action_B()
      .perform_some_action_C()

Name: Anonymous 2011-05-07 16:05

>>9, that's a good compromise

Name: Anonymous 2011-05-07 16:06

>>10 that's exactly the same as in >>2 you smelly cunt

Name: Anonymous 2011-05-07 16:09


void ExpertInternetTrollDispatcher::terminate_trolls() {
    if (destroy_trolls_) {
        try {
            for (std::vector<ExpertInternetTroll>::const_iterator itr = trolls_.begin(), end = trolls_.end(); itr != end; ++itr) {
                trolls.terminate();
            }
        }
        catch (...) {
            std::cout << "A troll tried to elude us!" << std::endl;
            throw;
        }

        trolls.clear();
    }
}

Name: Anonymous 2011-05-07 16:09

>>9
bar = object.perform_some_action_A()
            .perform_some_action_B()
            .perform_some_action_C()

Name: Anonymous 2011-05-07 16:10

i prefer the FIOC-friendly

bar = baz()
    .foo()
    .foo()
    .foo()
    .foo()
    .foo()
    ...


this is why code folding was invented

Name: Anonymous 2011-05-07 16:11

>>12
Whoops, I got carried away and forgot to make it correct:

void ExpertInternetTrollDispatcher::terminate_trolls() {
    if (destroy_trolls_) {
        try {
            for (std::vector<ExpertInternetTroll>::const_iterator itr = trolls_.begin(), end = trolls_.end(); itr != end; ++itr) {
                itr->terminate();
            }
        }
        catch (...) {
            std::cout << "A troll tried to elude us!" << std::endl;
            throw;
        }

        trolls_.clear();
    }
}

Name: Anonymous 2011-05-07 16:13

>>15
C++0x/C++11:

void ExpertInternetTrollDispatcher::terminate_trolls() {
    if (destroy_trolls_) {
        try {
            for (auto troll : trolls_) {
                troll.terminate();
            }
        }
        catch (...) {
            std::cout << "A troll tried to elude us!" << std::endl;
            throw;
        }

        trolls_.clear();
    }
}

Name: Anonymous 2011-05-07 16:14

>>15 you didn't learn anything in this thread, ftfy:

void ExpertInternetTrollDispatcher::terminate_trolls() {
    if (destroy_trolls_) {
        try {
            for (std::vector<ExpertInternetTroll>::const_iterator itr = trolls_.begin(),
                        end = trolls_.end();
                        itr != end;
                        ++itr) {
                itr->terminate();
            }
        }
        catch (...) {
            std::cout << "A troll tried to elude us!" << std::endl;
            throw;
        }
 
        trolls_.clear();
    }
}

Name: Anonymous 2011-05-07 16:28

>>17
That's ugly. Why bother when everyone has 1920x1080 or 1920x1200 displays. We never indent our code to line limits at work.

Name: Anonymous 2011-05-07 17:30

>>8
Really, you're unimaginative.
bar = object.perform_some_action_A()
bar = bar.perform_some_action_B()
bar = bar.perform_some_action_C()

You don't need to put them all on the same line.

Name: Anonymous 2011-05-07 17:35

>>8

((compose
  perform-some-action-c
  perform-some-action-b
  perform-some-action-a) object)

Name: Anonymous 2011-05-07 17:45

>>18
Remember, that variable's name should describe, what is stored in this variable. What if when bar.perform_some_action_B() returns something completely different, that bar.perform_some_action_C() ? Your concept is incorrect.

Name: Anonymous 2011-05-07 18:08

Even Perl6 has unspace:

$foo.bar\
    .baz\
    .quux;


I wanted to spaz over the unsightly line-ending '\' convention but it never seems to come up.

Perl6's real line lengthening issue is chained method calls, but feeds take care of that:

@foo.grep:   /^a/    ==>
    .map:    *.chars ==>
    .reduce: *+*

Or:

@foo.grep:   /^a/
==> .map:    *.chars
==> .reduce: *+*

Name: Anonymous 2011-05-07 18:11


@foo.grep:   /^a/
==> .map:    *.chars
==> .reduce: *+*


This looks too pretty for Perl. Also, an operator for everything

Name: Anonymous 2011-05-07 18:35

>>23
The ugly version is:

@foo.grep(/^a/).map({$_.chars}).reduce({$^a + $^b});

(You can unspace that as in >>22 instead of using feeds.)

Or the non-OO version:


reduce({ $^a + $^b }, map({ $_.chars }, grep(/^a/, @waldo)));
# i.e.:
reduce(
  { $^a + $^b },
  map(
    { $_.chars },
    grep(/^a/, @waldo)
  )
);


The worst thing you can do is mix the two. Imagine instead of @waldo, you have $waldo.split(/\s/).comb(/<[a..zA..Z]>/).

Name: Anonymous 2011-05-07 20:57

>>23
Btw that is a good example to illustrate the purpose of unspace. If you like to line things up and maybe format things a little differently you'll want unspace here and there:

@a\   .grep:   /^a/
  ==> .map:    *.chars
  ==> .reduce: *+*


(Though you could just feed into the initial .grep too.)

Don't change these.
Name: Email:
Entire Thread Thread List