7 ms·
I am a C# developer. My thoughts: - I love that they are adding REPL. I really wish C# had this. I use IPython all the time for Python. It is very helpful t
by pwaivers 9y ago
I am a C# developer. My thoughts:
- I love that they are adding REPL. I really wish C# had this. I use IPython all the time for Python. It is very helpful to mock something up quickly or try out different features.
- Adding private methods to an interface seems very wrong to me. An interface is just a contract without any implementation at all. I am not sure the reason behind this. Aren't abstract classes a thing in Java?
- I was sad to see that they have not included type inference to Java yet. It is just a syntax thing, but it makes writing code feel so much less wordy. Here's an open JEP for it: http://openjdk.java.net/jeps/286 http://openjdk.java.net/jeps/286
- josteink 9y ago> - I love that they are adding REPL. I really wish C# had this Here you go :) https://github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough https://github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkt... Also: csi.exe. Try it :)
- pents90 9y agoAs a long-time Java developer, I really hope they won't implement JEP 286. I think type inference by the compiler is a bad idea, as it results in less readable code, more bugs, and an unnecessary burden on the compiler. I think all the examples where type inference is convenient are trivial cases, but the downsides start to crop up in real-world, large code bases. So it's something that makes the easy things slightly easier and the hard the things harder. Type inference already happens for you when you are using a good IDE, like IntelliJ IDEA. You can just use the "Introduce Variable" refactoring. And better yet, it self-documents your code with the variable's type.
- deleted 9y ago[deleted]
- saosebastiao 9y agoI think you're suffering from Stockholm syndrome. I have never experienced a bug using scala's type inference that could have been prevented by more required boilerplate. Type inference is 100% benefit with zero drawback. If you really want to know what a type is resolved to, you have both compilers and IDEs there to tell you. Relying on an IDE to write code is just hacking over a weak or broken language.
- tormeh 9y agoTo be fair, the compiler errors you get with inferenced types will often lead you to write in the types anyway, to ringfence the bugs. Type inference often gives you really messed up error messages when you've done a mistake.
- pwaivers 9y ago> Less readable code Maybe it is because we are used to our own paradigms, but the following is no less readable to me because of inference. And these are the 95% of cases. var index = 0; var name = "pwaivers"; var names = new List<string>(); var nameMap = new List<string, Dictionary<int, Address>>(); > more bugs I have never seen a bug arise because of type inference. Do you have an example? > unnecessary burden on the compiler The compiler does a lot of work and this would probably be insignificant to add to it. However, I am totally open to learning more about this.
- meandmycode 9y agoYea, I remember the same was said when C# was introducing var, it's a valid concern but in reality it really isn't
- douche 9y agoThe only people I've seen complain much about this were converted VB devs, who mistakenly thought it was shorthand for the godawful VB Variant type, with all of its unintuitive type coercion rules that make JavaScript seem sane.
- kentosi 9y agoThe examples you've given have direct values. Try: var index = getIndexFromSomewhere(); var name = getHandleFromUser("peter", "waivers") The type isn't as clear anymore. *Edit: I'm absolutely a fan of the var syntax, having dabbled with scala. I'm just expressing what I think the original author's complaint is.
- coldtea 9y ago>The type isn't as clear anymore. It doesn't have to be, as the compiler (and linter) will inform of any misuse of the type later on. And any editor worth its salt could even annotate the type right there.
- mikepurvis 9y agoIsn't Java generally considered to be unusable without a decent IDE anyway? I feel like if you need to know what the return type is, the editor should be able to tell you that in these cases.
- coldtea 9y ago>As a long-time Java developer, I really hope they won't implement JEP 286. I think type inference by the compiler is a bad idea, as it results in less readable code, more bugs, and an unnecessary burden on the compiler. It is already the case in lots of languages since 1990s and the sky has not fallen...
- richard_todd 9y agoIt's not a compiler burden because it already has to determine the type of the right-hand side for typechecking purposes. So, the compiler actually does less work in the 'var' case, simply assigning the calculated type to the left-hand side rather than checking against a user-supplied type.
- tormeh 9y agoNot really. Without type inference, there's always a pretty short path to the type: For "int x = y" you only have to check that the type of y is int. If you have type inference "int x = y" is a lot harder to validate, because y may have been defined like so "var y = z". So now you have to create some kind of list of variables and their types, start at the ones that are explicitly defined like "int a = b" or "c = 5" and then fill in the types of the rest as you find a reference to the ones you know.
- pacala 9y agoIntellij: View type info [on Mac: Ctrl + Shift + P]. Of any [sub]expression. Whenever you care about that level of detail. On-demand self-documented code.
- nonsince 9y agoRust, ML, Coq and Haskell have type inference and if those four are known for anything it's reliability and bug-free code.
- swsieber 9y agoI like the private interfaces thing. It's getting us closer to having "mixin" ability through interfaces. I think if we had "protected" methods, we'd be there (assuming protected methods played nice with interface inheritance).
- aardvark179 9y agoSo at Java 8 they added the ability for interfaces to have default implementations - this was so that the collections API (among others) could be expanded with lots of support for the new lambda features without breaking compatibility. Allowing private methods means default implementations can be easily refactored to move common code to private methods without those internal methods themselves becoming part of the interface. Yes Java does have abstract types, but multiple inheritance is allowed from interfaces (which aren't structural) but not abstract types so interfaces are very widely implemented across the standard and other libraries.
- pwaivers 9y agoI did not realize that Java had implementations in interfaces already. This makes perfect sense why they would add the private method then. Thanks for answer!
- deleted 9y ago[deleted]
- daigoba66 9y ago> REPL. I really wish C# had this. Already exists: https://msdn.microsoft.com/en-us/magazine/mt614271.aspx https://msdn.microsoft.com/en-us/magazine/mt614271.aspx But I do a lot more these days with https://www.linqpad.net/ https://www.linqpad.net/ instead.
- deleted 9y ago[deleted]
- rzzzt 9y agoLombok implements "var" as an experimental feature: https://projectlombok.org/features/experimental/var.html https://projectlombok.org/features/experimental/var.html
- nine_k 9y agoInterface methods is an attempt to add traits to Java. I find it especially nice that interface methods are insulated between interfaces. I find traits a much better approach than traditional inheritance. You can inherit from only one base class; if Java had multiple inheritance, as C++ has, a number of other problems would arise.
- jjtheblunt 9y agoon your last point: they did, and it's called Scala. ;)