TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

I was wrong, reflecting on the .NET design choices

165 点作者 redknight666大约 8 年前

12 条评论

jasode大约 8 年前
If I attempt to generalize it, I think most of C#&#x27;s differences in language design that have opposites in Java are superior. Examples include:<p>+ not virtual by default (so base classes can be changed more easily without breaking&#x2F;recompiling downstream clients that the base class writer doesn&#x27;t know about; specifying something as &quot;virtual&quot; should be a deliberate conscious decision by the class author)<p>+ value types (for speed, because J Gosling&#x27;s idea that &quot;_everything_ is an object is &#x27;simpler&#x27; for programmers&quot; has a cost -- the boxing &amp; unboxing, and inefficient cache-unfriendly pointer-chasing containers)<p>+ no checked exceptions (checked exceptions have benefits in theory but real-world practice shows that it forces programmers to copy-paste mindless boilerplate to satisfy the checked-constraint)<p>+ unsigned types (very handy for P&#x2F;Invoke API boundaries because legacy Win32 has unsigned params everywhere; yes, yes, Gosling said that unsigned types are confusing and dangerous but nevertheless, they are still very useful)<p>+ many other examples<p>This doesn&#x27;t mean that Anders Hejlsberg&#x27;s C# language team was smarter than J Gosling&#x27;s Java team. They simply had 7 years to observe how Java programmers (mis)used the language and therefore, could correct some design mistakes.<p>Nevertheless, C# still made some dubious decisions such as renaming &quot;finalizers&quot; to &quot;destructors&quot;. Java had the better name and C# should have kept the original terminology.
评论 #14168264 未加载
评论 #14169697 未加载
评论 #14168059 未加载
评论 #14170156 未加载
评论 #14168007 未加载
评论 #14167691 未加载
klodolph大约 8 年前
Java and C# are seen as &quot;old news&quot; by some here on HN but there&#x27;s a trove of software engineering wisdom in there. It was a huge boon for Microsoft to be able to learn from Sun&#x27;s mistakes when they were designing a language that, on paper, is basically the same thing. C#, Java, and Go are all &quot;wonderfully boring&quot; languages which is a divisive topic, but they&#x27;re all very good at being boring languages.<p>It&#x27;s not just language features that made C# an improvement over Java, either. CIL is a fair bit more elegant than JVM bytecode. JVM bytecode has type-specific operations to speed up bytecode interpreters, which turns out to be irrelevant since nobody cares about bytecode performance these days.
评论 #14168065 未加载
评论 #14169152 未加载
dahart大约 8 年前
&gt; However, given that I’m working on a database engine now, not on business software, I can see a whole different world of constraints.<p>This might be my own confirmation bias, but this is my takeaway: point of view and the constraints that you see or believe are there are the main determinant of choices, and not whether some particular pattern or feature of a language is intrinsically good.<p>The older I get and the more code I write, the more I find this to be true. I change my own mind about things I used to argue fiercely over and things I thought were tautologically true.<p>I think (hope) this is making me more open minded as I go, more willing to listen to opposing points of view, and more able to ask questions about what someone else&#x27;s constraints are rather than debating about the results. But, who knows, I might be wrong.
评论 #14167928 未加载
评论 #14169651 未加载
hdhzy大约 8 年前
I think it&#x27;s valuable to read interviews with Anders Hejlsberg [0] about the design process for both .NET and C#. They are old but clearly communicate why certain decisions have been made (spoilers: compatibility).<p>[0]: <a href="http:&#x2F;&#x2F;www.artima.com&#x2F;intv&#x2F;anders.html" rel="nofollow">http:&#x2F;&#x2F;www.artima.com&#x2F;intv&#x2F;anders.html</a>
andrewvc大约 8 年前
You never really learn a language, and you never really are an expert in using it.<p>While you may know a lot about what the language is, how it works, and accepted ways of using it, your opinions on how to do things will always be evolving (hopefully).<p>Sometimes all the experts who use a language will be behind the times. For a long time experts championed strong OO design. Now all the experts champion hybrid OO&#x2F;FP style things (witness Java 8!).<p>This too shall pass, and we should have the humility to realize that no-one knows for certain what will be the next evolution of software development.
oop17大约 8 年前
One of the greatest lingering flaws in both C# and Java is the lack of metaclasses.<p>Because classes aren&#x27;t real objects and therefore not necessarily also instances of other classes (their metaclasses) as they would be in Smalltalk, there is no class-side equivalent of &quot;self&#x2F;this,&quot; nor of &quot;super.&quot; In effect, you cannot write static (class) methods that call other static methods without explicitly referencing the classes on which those other methods are defined, completely breaking class-side inheritance and rendering class behavior (and instance creation in particular) needlessly brittle.<p>I believe the explosion of factories, abstract factories, and just generally over-engineered object construction and initialization schemes in Java and C# would have been side-stepped if both languages had always had a proper metaclass hierarchy paralleling the regular class hierarchy, as well as some form of local type inference.
评论 #14167990 未加载
评论 #14167902 未加载
评论 #14169637 未加载
评论 #14168002 未加载
hyperpape大约 8 年前
While I&#x27;m inclined to suspect that non-virtual by default is better from a design perspective‡, don&#x27;t assume the point about performance is overwhelming. HotSpot has done devirtualization for a long time. You can detect not only when a method is never overridden, but also when it&#x27;s never overridden at a particular call site. A virtual method that&#x27;s never overridden can sometimes have no extra overhead, while a virtual method that is overridden may have sufficiently small overhead that it rarely matters.<p><a href="http:&#x2F;&#x2F;insightfullogic.com&#x2F;2014&#x2F;May&#x2F;12&#x2F;fast-and-megamorphic-what-influences-method-invoca&#x2F;" rel="nofollow">http:&#x2F;&#x2F;insightfullogic.com&#x2F;2014&#x2F;May&#x2F;12&#x2F;fast-and-megamorphic-...</a><p>‡ I&#x27;ve used non-OO languages, but never an OO language without virtual by default.
评论 #14168618 未加载
评论 #14169197 未加载
评论 #14169356 未加载
matchagaucho大约 8 年前
<i>&quot;Another issue is that my approach to software design has significantly changed. Where I would previously do a lot of inheritance and explicit design patterns, I’m far more motivated toward using composition, instead.&quot;</i><p>This, more than anything, has dramatically improved the quality of my designs... and made coding fun again.<p>Immutability and Lambda functions have also had a tremendous impact on my designs.<p>Is the term <i>Object-Oriented-Programming</i> relevant anymore?
评论 #14170219 未加载
marsrover大约 8 年前
I&#x27;m surprised the creator of RavenDB took this long to come around on composition vs inheritance. Good on him for admitting his transgressions, however.
评论 #14167630 未加载
PaulHoule大约 8 年前
Java is not &quot;virtual by default&quot;, it is virtual-only, except for private methods, which don&#x27;t participate in inheritence.<p>I like the Java convention, for one thing, because it is one less decision for programmers to make. I&#x27;ve seen many C# programmers who are oblivious to what virtual means.
评论 #14168574 未加载
amag大约 8 年前
<i>&quot;Someone was wrong on the Internet, it was me.&quot;</i>
martamoreno大约 8 年前
The bigger question is why the hell a post like this makes it on top of hacker news? This was by far the most pointless read ever.<p>On top of that arguing that non-virtual by default is worse than virtual by default is completely superfluous. Just add the damn keyword everywhere and you have virtual everywhere. Same for final.<p>But Java has everything non-final and virtual by default, which sucks badass because both require great care when implementing the method.<p>Extending code that was not designed to be extended is very common in Java, because you can. Adding final can easily be forgotten. Removing final, which is required in C#, will only be done IF you intended to make that method extendable, same for virtual.<p>Yes a great gain. Now I need to argue for each final I add to Java classes and methods, because you know, it seems wasteful to add it, while in fact it is crucial, since maybe just 1% of any code I write was meant to be replaceable by a third-party. Mostly, you want to use other mechanism for extension, like decoration &amp; composition.<p>If it took ten years to learn that falsehood (non-virtual is worse than virtual by default), then we talk about one hell of a regression huh.
评论 #14168179 未加载
评论 #14167827 未加载