static-typing

Can someone tell me what Strong typing and weak typing means and which one is better?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 10:16:37
问题 Can someone tell me what Strong typing and weak typing means and which one is better? 回答1: That'll be the theory answers taken care of, but the practice side seems to have been neglected... Strong-typing means that you can't use one type of variable where another is expected (or have restrictions to doing so). Weak-typing means you can mix different types. In PHP for example, you can mix numbers and strings and PHP won't complain because it is a weakly-typed language. $message = "You are

Disadvantages of Scala type system versus Haskell?

心不动则不痛 提交于 2019-11-27 09:24:26
问题 I have read that Scala's type system is weakened by Java interoperability and therefore cannot perform some of the same powers as Haskell's type system. Is this true? Is the weakness because of type erasure, or am I wrong in every way? Is this difference the reason that Scala has no typeclasses? 回答1: The big difference is that Scala doesn't have Hindley-Milner global type inference and instead uses a form of local type inference, requiring you to specify types for method parameters and the

Tools for static type checking in Python

强颜欢笑 提交于 2019-11-26 19:56:42
问题 I'm working with a large existing Python codebase and would like to start adding in type annotations so I can get some level of static checking. I'm imagining something like Erlang, Strongtalk, or Typed Scheme/Racket. I've seen quick-and-dirty decorators that insert dynamic checks based on function parameter and return type annotations, but I'm looking for something that is more robust and that performs checks at compile-time. What tools are available right now for this kind of thing? I'm

Why is C# statically typed?

我的未来我决定 提交于 2019-11-26 16:01:26
问题 I am a PHP web programmer who is trying to learn C#. I would like to know why C# requires me to specify the data type when creating a variable. Class classInstance = new Class(); Why do we need to know the data type before a class instance? 回答1: As others have said, C# is static/strongly-typed. But I take your question more to be "Why would you want C# to be static/strongly-typed like this? What advantages does this have over dynamic languages?" With that in mind, there are lots of good

Static/Dynamic vs Strong/Weak

混江龙づ霸主 提交于 2019-11-26 11:57:45
I see these terms bandied around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I'm aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different meanings or even use the terms interchangeably. I can't find somewhere that talks about both and actually spells out the difference. What would be nice is if someone could please spell this out clearly here for me and the rest

What is the difference between a strongly typed language and a statically typed language?

放肆的年华 提交于 2019-11-26 10:56:45
Also, does one imply the other? What is the difference between a strongly typed language and a statically typed language? A statically typed language has a type system that is checked at compile time by the implementation (a compiler or interpreter). The type check rejects some programs, and programs that pass the check usually come with some guarantees; for example, the compiler guarantees not to use integer arithmetic instructions on floating-point numbers. There is no real agreement on what "strongly typed" means, although the most widely used definition in the professional literature is

Does Java casting introduce overhead? Why?

。_饼干妹妹 提交于 2019-11-26 10:24:03
Is there any overhead when we cast objects of one type to another? Or the compiler just resolves everything and there is no cost at run time? Is this a general things, or there are different cases? For example, suppose we have an array of Object[], where each element might have a different type. But we always know for sure that, say, element 0 is a Double, element 1 is a String. (I know this is a wrong design, but let's just assume I had to do this.) Is Java's type information still kept around at run time? Or everything is forgotten after compilation, and if we do (Double)elements[0], we'll

What is the purpose of type ascriptions in Scala?

此生再无相见时 提交于 2019-11-26 03:51:21
问题 There\'s not much info in the spec on what type ascription is, and there certainly isn\'t anything in there about the purpose for it. Other than \"making passing varargs work\", what would I use type ascription for? Below is some scala REPL for the syntax and effects of using it. scala> val s = \"Dave\" s: java.lang.String = Dave scala> val p = s:Object p: java.lang.Object = Dave scala> p.length <console>:7: error: value length is not a member of java.lang.Object p.length ^ scala> p.getClass

Does Java casting introduce overhead? Why?

这一生的挚爱 提交于 2019-11-26 03:28:30
问题 Is there any overhead when we cast objects of one type to another? Or the compiler just resolves everything and there is no cost at run time? Is this a general things, or there are different cases? For example, suppose we have an array of Object[], where each element might have a different type. But we always know for sure that, say, element 0 is a Double, element 1 is a String. (I know this is a wrong design, but let\'s just assume I had to do this.) Is Java\'s type information still kept

Static/Dynamic vs Strong/Weak

两盒软妹~` 提交于 2019-11-26 02:25:52
问题 I see these terms bandied around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I\'m aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different meanings or even use the terms interchangeably. I can\'t find somewhere that talks about both and actually spells out the