language-features

How does your favorite language handle deep recursion? [closed]

坚强是说给别人听的谎言 提交于 2019-11-28 17:12:20
问题 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 6 years ago . I recently started learning Python and I was rather surprised to find a 1000 deep recursion limit (by default). If you set it high

What's the new way to iterate over a Java Map in Scala 2.8.0?

半城伤御伤魂 提交于 2019-11-28 17:08:38
问题 How does scala.collection.JavaConversions supercede the answers given in Stack Overflow question Iterating over Java collections in Scala (it doesn't work because the "jcl" package is gone) and in Iterating over Map with Scala (it doesn't work for me in a complicated test which I'll try to boil down and post here later). The latter is actually a Scala Map question, but I think I need to know both answers in order to iterate over a java.util.Map . 回答1: In 2.8, you import scala.collection

What's so great about Scala? [closed]

人走茶凉 提交于 2019-11-28 15:02:34
What makes Scala such a wonderful language, other than the type system? Almost everything I read about the language brings out 'strong typing' as a big reason to use Scala, but there has to be more than that. What are some of the other compelling and/or cool language features that make Scala a really useful tool? Here are some of the things that made me favour Scala (over, say, usual Java): a) Type inference. The Java way of doing it: Map<Something, List<SomethingElse>> list = new HashMap<Something, List<SomethingElse>>() .. is rather verbose compared to Scala. The compiler should be able to

What is the purpose of long, double, byte, char in Java?

喜欢而已 提交于 2019-11-28 14:28:26
问题 So I'm learning java, and I have a question. It seems that the types int , boolean and string will be good for just about everything I'll ever need in terms of variables, except perhaps float could be used when decimal numbers are needed in a number. My question is, are the other types such as long , double , byte , char etc ever used in normal, everyday programming? What are some practical things these could be used for? What do they exist for? 回答1: With the possible exception of "short",

Samples of Scala and Java code where Scala code looks simpler/has fewer lines?

霸气de小男生 提交于 2019-11-28 13:15:12
问题 I need some code samples (and I also really curious about them) of Scala and Java code which show that Scala code is more simple and concise then code written in Java (of course both samples should solve the same problem). If there is only Scala sample with comment like "this is abstract factory in Scala, in Java it will look much more cumbersome" then this is also acceptable. Thanks! I like most of all accepted and this answers 回答1: Let's improve stacker's example and use Scala's case

java partial classes

夙愿已清 提交于 2019-11-28 12:14:21
Small preamble. I was good java developer on 1.4 jdk. After it I have switched to another platforms, but here I come with problem so question is strongly about jdk 1.6 (or higher :) ). I have 3 coupled class, the nature of coupling concerned with native methods. Bellow is example of this 3 class public interface A { public void method(); } final class AOperations { static native method(. . .); } public class AImpl implements A { @Override public void method(){ AOperations.method( . . . ); } } So there is interface A, that is implemented in native way by AOperations, and AImpl just delegates

ForEach loop in Mathematica

为君一笑 提交于 2019-11-28 09:47:20
I'd like something like this: each[i_, {1,2,3}, Print[i] ] Or, more generally, to destructure arbitrary stuff in the list you're looping over, like: each[{i_, j_}, {{1,10}, {2,20}, {3,30}}, Print[i*j] ] Usually you want to use Map or other purely functional constructs and eschew a non-functional programming style where you use side effects. But here's an example where I think a for-each construct is supremely useful: Say I have a list of options (rules) that pair symbols with expressions, like attrVals = {a -> 7, b -> 8, c -> 9} Now I want to make a hash table where I do the obvious mapping of

Is it costly to do array.length or list.count in a loop

笑着哭i 提交于 2019-11-28 09:42:59
I know that in JavaScript, creating a for loop like this: for(int i = 0; i < arr.length; i++) is costly as it computes the array length each time. Is this behavior costly in c# for lists and arrays as well. Or at compile-time is it optimized? Also what about other languages such as Java, how is this handled? It is not costly in C#. For one thing, there is no “calculation“: querying the length is basically an elementary operation thanks to inlining. And secondly, because ( according to its developers ), the compiler recognizes this pattern of access and will in fact optimize any (redundant)

How can I get the callee in PHP? [duplicate]

柔情痞子 提交于 2019-11-28 09:04:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Caller function in PHP 5? I would like to know from where a global function or public method is being called. I guess I could do it by inspecting debug_backtrace but I'd rather use a lighterweight mechanism if one exists. Any suggestions? For example something like so, if you imagine the get_callee() function and constant existing: function doSomething() { if(get_callee() == 'PHP_GLOBAL') { throw new

What is the name of a [foo, bar] = [“foo”, “bar”] feature?

怎甘沉沦 提交于 2019-11-28 08:27:52
I need to know a correct name for this cool feature that some languages provide. FYI: In some languages it is possible to do a multiple assignments by assigning a structure of values to a structure of "variables". In the example in the question title it assigns "foo" to foo and "bar" to bar. It's generally called destructuring bind in functional languages (which don't have assignments) and destructuring assignment in imperative languages. Some languages provide subsets of that feature and then call it something different. For example, in Python it works with Tuples, Lists or Sequences and is