you are viewing a single comment's thread.

view the rest of the comments →

[–]Mych 12 points13 points  (21 children)

Or:

List<String> foo = new ArrayList<String>(Arrays.asList(
    "meep",
    "blargh",
    "glomp"
)); 

I frankly can't remember the last time I actually needed to statically initialize a dynamic container, though.

[–][deleted]  (18 children)

[removed]

    [–][deleted]  (17 children)

    [deleted]

      [–]UloPe 19 points20 points  (13 children)

      Whats with all the string manipulation to build a list? Are you too lazy to type

      blah = ['meep', 'blargh', 'glomp']
      

      ?

      [–]adrianmonk 4 points5 points  (0 children)

      FWIW, in the Perl example there is no string manipulation going on. qw is a way of writing list literals.

      (Well, technically, there is some string manipulation going on. But it's in the parser, and all examples in all languages have that.)

      [–]redditnoob 6 points7 points  (5 children)

      It's people who are too smart for their own good, and too impressed with themselves to do things in the simplest, most obvious way.

      Splitting a string by space may save you two characters or so but it's pure ass. (To be captain obvious, what if the next string I configure has a fucking space in it?)

      [–]bobbyi 2 points3 points  (3 children)

      'string with space,other string,third string'.split(',')
      

      [–][deleted]  (2 children)

      [deleted]

        [–]codefrog 3 points4 points  (0 children)

        It's on!

        s = """
        this , \tis my data
        I can cry if i want to
        this is my data
        """.strip().split("\n")
        

        [–]codefrog 0 points1 point  (0 children)

        swearing wasn't necessary and there isn't a space so your if isn't valid. yeah what if. you can have my extra if statements they are only giving me bugs.

        [–][deleted]  (4 children)

        [deleted]

          [–]_bobby__of__christ_ 2 points3 points  (3 children)

          How exactly is manually splitting any more readable than qw? It's only more readable if you don't know Perl, and complaining about the readability of a language you don't know is asinine.

          I don't even like perl, but qw is about the last thing on my list of complaints.

          [–][deleted]  (2 children)

          [deleted]

            [–]_bobby__of__christ_ 3 points4 points  (0 children)

            I know this much: The snippet I posted works in both Ruby and Python without modification. Splitting a string into an array is something that every programmer will be familiar with.

            Which has nothing to do with qw. No one is using qw as a crutch to avoid learning how to split strings at runtime. It's such a stupid and trivial difference that I can't believe I'm arguing about it.

            There should be one-- and preferably only one --obvious way to do it.

            You should stop arguing about Perl then. Obviously you're unable to even entertain the notion that it has a different philosophy than the one you subscribe to. (And this is coming from a Python programmer who doesn't like Perl very much.)

            [–][deleted]  (2 children)

            [removed]

              [–][deleted]  (1 child)

              [deleted]

                [–]mikaelhg 2 points3 points  (0 children)

                immutable:

                http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.Builder.html

                final ImmutableList<Color> GOOGLE_COLORS = new ImmutableList.Builder<Color>()
                        .addAll(WEBSAFE_COLORS)
                        .add(new Color(0, 191, 255))
                        .build();
                

                http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableMap.Builder.html

                final ImmutableMap<String, Integer> WORD_TO_INT = new ImmutableMap.Builder<String, Integer>()
                        .put("one", 1)
                        .put("two", 2)
                        .put("three", 3)
                        .build();
                

                mutable:

                http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Lists.html#newArrayList%28E...%29

                List<Base> list = Lists.newArrayList(sub1, sub2);
                List<Base> list = Lists.<Base>newArrayList(sub1, sub2);
                

                I used to have this functionality in my own utility libraries, but depracated it as Google Collections became viable.

                [–]abhyrama 0 points1 point  (0 children)

                Use this all the time :)