strong-typing

Why can't I inherit from int in C++?

帅比萌擦擦* 提交于 2019-11-27 12:16:44
I'd love to be able to do this: class myInt : public int { }; Why can't I? Why would I want to? Stronger typing. For example, I could define two classes intA and intB , which let me do intA + intA or intB + intB , but not intA + intB . "Ints aren't classes." So what? "Ints don't have any member data." Yes they do, they have 32 bits, or whatever. "Ints don't have any member functions." Well, they have a whole bunch of operators like + and - . Neil's comment is pretty accurate. Bjarne mentioned considering and rejecting this exact possibility 1 : The initializer syntax used to be illegal for

Compile Time Reflection in C#

泪湿孤枕 提交于 2019-11-27 10:54:02
问题 I frequently write C# code that has to use magic strings to express property names. Everyone knows the problems with magic strings. They are very difficult to refactor, they have no compile time checking, and often they lead to hard-to-diagnose issues. Yet C#/.NET uses them all over the place to represent property/class/method names. This issue has persisted for years and years, and the only viable solution currently is to use an expression tree which is then parsed at run-time for the

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

How far to go with a strongly typed language?

心不动则不痛 提交于 2019-11-27 05:15:27
问题 Let's say I am writing an API, and one of my functions take a parameter that represents a channel, and will only ever be between the values 0 and 15. I could write it like this: void Func(unsigned char channel) { if(channel < 0 || channel > 15) { // throw some exception } // do something } Or do I take advantage of C++ being a strongly typed language, and make myself a type: class CChannel { public: CChannel(unsigned char value) : m_Value(value) { if(channel < 0 || channel > 15) { // throw

Is there a good strongly typed way to do PropertyChanged events in C#?

大城市里の小女人 提交于 2019-11-27 04:26:01
问题 It must be a somewhat common event to change the name of a property and expect the Rename functionality in Visual Studio to take care of all the necessary renaming, except for the property name of the PropertyChanged event of INotifyPropertyChanged. Is there a better way to somehow get it strongly typed so you don't need to remember to manually rename it? 回答1: Edit: nameof arrived in c# 6. Yay! There is no nameof / infoof etc; this is much discussed, but it is what it is. There is a way to do

Is C++ considered weakly typed? Why?

混江龙づ霸主 提交于 2019-11-27 03:14:54
问题 I've always considered C++ to be one of the most strongly typed languages out there. So I was quite shocked to see Table 3 of this paper state that C++ is weakly typed. Apparently, C and C++ are considered weakly typed since, due to type-casting, one can interpret a field of a structure that was an integer as a pointer. Is the existence of type casting all that matters? Does the explicit-ness of such casts not matter? More generally, is it really generally accepted that C++ is weakly typed?

What are the key aspects of a strongly typed language?

我的梦境 提交于 2019-11-27 03:12:30
问题 What makes a language strongly typed? I'm looking for the most important aspects of a strongly typed language. Yesterday I asked if PowerShell was strongly typed, but no one could agree on the definition of "strongly-typed", so I'm looking to clarify the definition. Feel free to link to wikipedia or other sources, but don't just cut and paste for your answer. 回答1: The term "strongly typed" has no agreed-upon definition. It makes a "great" argument in a flamewar, because whenever someone is

What does strict types do in PHP?

拟墨画扇 提交于 2019-11-27 00:19:11
问题 I've seen this new line in PHP7 but nobody really explains what it means. I've googled it and all they talk about is will you be enabling it or not like a poll type of thing. declare(strict_types = 1); What does it do? How does it affect my code? Should I do it? Some explanation would be nice. 回答1: From Treehouse blog : With PHP 7 we now have added Scalar types. Specifically: int, float, string, and bool. By adding scalar type hints and enabling strict requirements, it is hoped that more

What are Java's primitive types? [duplicate]

夙愿已清 提交于 2019-11-26 22:33:05
问题 This question already has answers here : What's the difference between primitive and reference types? (7 answers) Closed last year . What are primitive type in Java? What is the difference between a primitive type and a reference type? How many primitive types does Java have, and what are they? 回答1: In Java, every variable has a type declared in the source code. There are two kinds of types: reference types and primitive types. Reference types are references to objects. Primitive types

Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

♀尐吖头ヾ 提交于 2019-11-26 21:49:18
Can I make a NSMutableArray instance where all the elements are of type SomeClass ? You could make a category with an -addSomeClass: method to allow compile-time static type checking (so the compiler could let you know if you try to add an object it knows is a different class through that method), but there's no real way to enforce that an array only contains objects of a given class. In general, there doesn't seem to be a need for such a constraint in Objective-C. I don't think I've ever heard an experienced Cocoa programmer wish for that feature. The only people who seem to are programmers