language-design

Programming Language Properties that facilitate refactoring?

混江龙づ霸主 提交于 2019-12-09 17:09:06
问题 What are common traits/properties of programming languages that facilitate (simplify) the development of widely automated source code analysis and re-engineering (transformation) tools? I am mostly thinking in terms of programming language features that make it easier to develop static analysis and refactoring tools (i.e. compare Java vs. C++, the former of which has better support for refactoring). In other words, a programming language that would be explicitly designed to provide support

Why is the scope of if and delegates this way in c#

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 16:48:22
问题 Inspired by this question I began wondering why the following examples are all illegal in c#: VoidFunction t = delegate { int i = 0; }; int i = 1; and { int i = 0; } int i = 1; I'm just wondering if anyone knew the exact reason why the language was designed this way? Is it to discourage bad programming practice, and if so why not just issue a warning?, for performance reasons (compiling and when running) or what is the reason? 回答1: This behavior is covered in section 3 of the C# language

In Java, how can I avoid raw types when calling getClass on an instance of a generic type?

南楼画角 提交于 2019-12-09 16:23:39
问题 Suppose I have this in Java: List<String> list = new ArrayList<String>(); list.getClass(); The type of the last expression is Class<? extends List> . I understand why, due to erasure, it cannot be Class<? extends List<String>> . But why can't it be Class<? extends List<?>> ? Is there no way for me to avoid both unchecked cast warnings and raw type warnings if I want to assign the result of this expression to a variable that somehow keeps the information that this class is actually some kind

Why does java have no byte type suffix? [closed]

大憨熊 提交于 2019-12-09 15:18:44
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago . So java has a long type suffix for literals: (123L), a double type suffix (43.21D), a floating point suffix (1.234F). So ... why no

What is the point of make_heap?

自闭症网瘾萝莉.ら 提交于 2019-12-09 07:22:54
问题 Can someone please tell me the point of the STL heap function templates like std::make_heap ? Why would anyone ever use them? Is there a practical use? 回答1: If you want to make a priority queue out from a list, well, you can use make_heap: Internally, a heap is a tree where each node links to values not greater than its own value. In heaps generated by make_heap, the specific position of an element in the tree rather than being determined by memory-consuming links is determined by its

How could an idiomatic design of Serializable/Cloneable/… look like in Scala?

旧巷老猫 提交于 2019-12-09 05:32:47
问题 I wonder how much different these funcionality would look like (and how different the implementation would be), if Scala wouldn't (have to) follow Java's java.io.Serializable / java.lang.Cloneable (mostly to stay compatible with Java and the tools/ecosystem around it). Because Scala is more simpler in language design, but enables more powerful implementation and abstraction possibilities, it is thinkable that Scala might take a different path compared to Java, if it wouldn't have to shoulder

Why do we have to name interface method parameters?

℡╲_俬逩灬. 提交于 2019-12-09 02:10:23
问题 In C# we have to name the parameters of a method of an interface. I understand that even if we didn't have to, doing so would help a reader understand the meaning, however in some cases it's not really needed: interface IRenderable { void Render(GameTime); } I would say the above is as readable and meaningful as the below: interface IRenderable { void Render(GameTime gameTime); } Is there some technical reason why names for parameters of methods on an interface are required? It's worth noting

Why doesn't Array override the triple equal sign method in Ruby?

独自空忆成欢 提交于 2019-12-08 21:04:13
问题 I've just noticed that Array doesn't override the triple equal sign method === , which is sometimes called the case equality method. x = 2 case x when [1, 2, 3] then "match" else "no match" end # => "no match" whereas the range operator does: x = 2 case x when 1..3 then "match" else "no match" end # => "match" You can do a workaround for arrays, however: x = 2 case x when *[1, 2, 3] then "match" else "no match" end # => "match" Is it known why this is the case? Is it because it's more likely

Does Perl language aim at producing fast programs at runtime?

岁酱吖の 提交于 2019-12-08 20:46:13
问题 I recently had a friend tell me "see perl was never designed to be fast" Is that true? The relevant piece of information I can find is this from Wikipedia: The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). But it doesn't directly talk about speed. I think that with all the text processing that it needs to do, speed of execution really matters for a language like Perl. And with all the weird syntax, elegance was never an

Differences when overriding inherited constructor fields?

瘦欲@ 提交于 2019-12-08 19:15:46
问题 Consider this simple Scala class: class A(val d: Int) Is there a difference in Scala (either in behaviour or generated bytecode) between class B(d: Int) extends A(d) and class B(override val d: Int) extends A(d) or are both equivalent? If they are different, what would be the specific usecase for each of them? Would it be different if A was defined as class A(var d: Int) ? 回答1: For vals, there is no semantic difference. However, there may be a difference in the generated bytecode . In