It's been a long time since I left the site, so I'm practicing Java 8.
It is possible to write Java8 like Java6, and I know that there are many sites where it will happen if you match it to the lowest level of the programmer, but now the idea that useful things should be incorporated and improved. Does not change.
I've created a fucking code, so I'm ashamed to publish it.
python
//Imagine if you want to create a lot of test data.
//bad example
List<MyObject> objs = Stream.of(1, 2, 3, 4, 5).map(i -> {
MyObject myObj = new MyObject();
/*Do various things*/
return myObj;
}).collect(Collectors.toList());
//Good example
// IntStream#range()If so, 5 will not come out, so be careful
List<MyObject> objs = IntStream.rangeClosed(1, 5).mapToObj(i -> {
MyObject myObj = new MyObject();
/*Do various things*/
return myObj;
}).collect(Collectors.toList());
My boom is to make the variable names of the collection plural (-s, -es). If you name it like xxxList, it feels like Hungarian and it feels uncomfortable, and there is a possibility that the type will not be List, so I've been confused for about 5 years.
I wondered if I couldn't write it like Perl, so I spent about 30 minutes trying and error. I wrote the argument of Stream # of () as 1.5, but it doesn't work. It's Java, not Perl.
python
#Note: Perl-like writing
my @array = (1 .. 5);
By the way, is Perl still active?
At the same time as the Struts stop campaign, a lot of Perl application abolition projects came and it was quite awkward. I want to replace it, but there is no design document, and there are few engineers who can reverse engineer.
I've been letting Python do all the little things these days. I'm good at writing Perl, but it's inconvenient that I can't use CPAN in an environment disconnected from the Internet ...
Recommended Posts