Поздравляю всех коллег — любителей java!
Пример кода:
List<Widget> widgets = ... ; int sum = widgets.stream() .filter(MyClass::isRed) .mapToInt(w -> w.getWeight()) .sum(); public static boolean isRed(Widget w) { return w.getColor() == RED; }
То о чём так долго говорили большевики — свершилось!
Лямбды и ссылки на методы, а главное туча непонятных вещей требующих изучения — в классах типа Stream, Collector, Consumer, BiConsumer и т.п. :)
great copy of
C#
features ! Congratulations :DOf course, because originally it was implemented in C#
you are right .
but take look at
c++11
, they took it fromC#
(and/orhaskell
) and made it more powerful . they didn't just copy/past the syntax !Implementation of delegates in
C#
is not efficient at all. Hope that at leastjava
implementation learned fromC#
.Oh, enjoy yourself with any lulling about having these features in any languages you want :)
Anyway C++ will never have reflection and C#'s nuget will never be even the dim ghost of what maven is.
P.S. Implementation of these new features in java is not perfect — closures are not closures in fact but simply implicit finals — and all this horrible mess with streams — it will do much headache to people learning java. However there are many nice ideas, approaches to parallel collections processing etc.
So I am just glad the Java is moving forward. I have no intention to compare it to languages which I'll never want to use. I write much in Java and PHP, Python — I'm eager to learn Haskell or perhaps Erlang — but I have no great motivation to learn C# — there is nothing special it will give me except the headache about windows servers etc.
C++ makes very few guarantees about the compiled code. The compiler is allowed to do pretty much anything it likes, as long as the resulting functionality is what is expected. For example, your classes aren't required to actually be there. The compiler can optimize them away, inline everything they do, and it frequently does just that, because even simple template code tends to create quite a few template instantiations. The C++ standard library relies on this aggressive optimization. Functors are only performant if the overhead of instantiating and destructing the object can be optimized away. operator[] on a vector is only comparable to raw array indexing in performance because the entire operator can be inlined and thus removed entirely from the compiled code. C# and Java make a lot of guarantees about the output of the compiler. If I define a class in C#, then that class will exist in the resulting assembly. Even if I never use it. Even if all calls to its member functions could be inlined. The class has to be there, so that reflection can find it. Part of this is alleviated by C# compiling to bytecode, which means that the JIT compiler can remove class definitions and inline functions if it likes, even if the initial C# compiler can't. In C++, you only have one compiler, and it has to output efficient code. If you were allowed to inspect the metadata of a C++ executable, you'd expect to see every class it defined, which means that the compiler would have to preserve all the defined classes, even if they're not necessary.
To be honest I did not understand what you wanted to express. :)
If it is all about my mention of incapability of C++ to have reflection — then relax. I used C/C++ for 10 years, I have significant experience with several assembly languages and I know well why it is so.
However for needs of business projects to have reflection is good and to have manual memory management is bad. So unless I'm going to return to programming routers and more cunning electronics — I have no ideas why I need to use C/C++.
UPD: on the other hand, of course, I believe C++ will never seize to be most important and influential in the world of Competitive Programming.
You know — for any task it is just important to choose a proper tool.
:D
Can I ask what reflection is so often used for (in business projects)? I've used it only once, implementing a plugin system.
2 examples that i worked with : Objec Srialization (JSON for example(for restfull http services)) . Orm(object relational mapping) for database access .
Yes, it's not that standard C++ library containers and helper classes do it automatically, right?
А такие вещи как
parallel()
в Java и\илиAsParallel()
в C# вообще в спортивном программировании используются? Расскажите, кто использует эти языки на контестах.Думаю, что это бессмысленно везде, кроме GCJ/FBHC — в остальных соревнованиях обычно меряется суммарное процессорное время по всем ядрам, то есть время только ухудшается из-за накладных расходов на синхронизацию и делёж общего кэша между ядрами.
Осталось дождаться Java 8 в списке языков на Codeforce :)
Java8 tutorial here