Swift strictness [closed] - swift

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Well, it says on their website that Swift is a strict language. However, I am not sure in what ways it is considered to be strict. Can you please elaborate on that?

Statements about the nature of Swift are often expressed in terms meaningful to people accustomed to the previous language, Objective-C. So in this case, the statement that Swift is "strict" typically refers to how things like variables are typed. But unless you have used another language like Objective-C or Ruby that is not strict about typing, you probably won't appreciate the difference.
For example, in Objective-C, programmers often use "dynamic typing", where a variable is typed as id and you can assign to it a value of any type, even different types at different times — now an NSString, now an NSNumber, now a UIView. But in Swift you can't do that; once we've established that this variable is a String, its value can only ever be a String.
Similarly, in Objective-C, NSArray is just "a collection of objects" of any old type. But in Swift, an Array is a collection of just one type of object and you have to say in advance exactly what type it is.

Related

Are there copy constructors in Swift structures? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
It's known, that when assigning an instance of structure to another instance, or passing it to a function, Swift essentially copies the instances by value. However I could not find anywhere if we actually have control over this process, like in C++ copy constructors. My question is whether Swift has analogue to C++ copy constructors and if not, are there anything in the language what helps to take control over passing-by-value process in Swift?
Copy constructors are implicit in Swift, and can't be user-customized.
They always copy all fields of a struct. For fields that are references to object, copying is defined as the increment of reference count (a retain).

Is type declaration a big part of the positives of static typed languages? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Statically typed programming languages do type checking at compiling. Is type declaration an important reason that is making them significantly faster?
A statically typed language is one in which the type of every variable is known at compile-time. In some languages like C, C++, Java the programmer must manually specify the type and in other languages like Haskell and Scala has some form of type inference, the capability of the type system to deduce the type of a variable.
Does it make them faster?
1. Figuring out the type at compile-time does reduce a lot of overhead for the run-time.
2. Because the types are figured out earlier on, even functions/ methods in the language are well defined into static addresses. Where as in a dynamically typed language names are based on strings. And for each method access, lookups have to be done. Which are many, causing the language to be slower.
yes static declarations of variables improves execution speed

How Nothing can be subclass of all types when multiple inheritance is not supported in scala [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
This is more of conceptual question i stumbled upon. Scala states than multiple inheritance is not supported but at same time states than "Nothing" is subclass of all types. Isn't this against the concept that Scala states.
Scala states than multiple inheritance is not supported
That is not true. Scala supports linearized multiple mixin inheritance.
but at same time states than "Nothing" is subclass of all types.
That is not true. The documentation clearly states that Nothing extends Any, and that's it. It is only a subclass of Any, and nothing else.
The documentation also states (bold emphasis mine):
Nothing is a subtype of every other type (including scala.Null)
As you can see, nowhere does the documentation say that Nothing is a subclass of all types. It only says it is a subtype of all types, which is completely different.
Isn't this against the concept that Scala states.
No, it is not.
But even if what you are saying were true, there is still no contradiction: the Scala Language Specification defines what "Scala" is, and if the SLS says that Nothing is a subclass of all classes, then that's how it is. The Scala Language Specification say anything it wants, and this will never be against the concepts of Scala, because the Scala Language Specification defines the concepts of Scala.
Now, as it turns out, your premise was wrong, and the Scala Language Specification does not say that Nothing has multiple superclasses, but it could say that if it wanted, and that would not be against the concepts of Scala, because the Scala Language Specification says what, exactly, the concepts of Scala are.

What is a good naming convention for Unity? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm pretty much a noob with Unity. As a c++ programmer, the naming conventions in Unity bothers me a little. And having OCD ontop of that makes me go crazy ;)
The objects has say a property Transform which again has a property Position.
But these properties must be accessed by writing transform.position in the code using lower case. This is not very intuitive to me. So I wonder how I can look at it in order to more easily avoid complications. And what conventions I should use to be able to tell everything appart by taking a quick look at the variables.
The Unity convention is actually rather simple: everything is Pascal-cased, types (classes, structs, enums) and methods start with upper-case, fields and properties with lower-case. Enum values in upper-case, constants in lower-case (usually).
So ClassName, MethodName, myField, myProperty { get; set; }, MyEnum.CaseA... that's it.
As for your example, Transform is a class, whereas transform is an accessor to the instance of Transform in that particular GameObject/Component.
Also, Transform doesn't have a Position property, it has a position property (always lower-case).
This is more or less based on C#'s conventions and the standard .NET library (MS has very precise guidelines about it), except standard .NET uses UpperCase for public/protected methods AND properties, and lower-case for private (again, usually; what's private is more left to the taste of the coder I think).
As a side-note, with any codebase, in any language, the best way is ALWAYS to follow the existing convention. Every seasoned programmer will tell you this. I understand about OCD, believe me, but in this case I suggest you let it go.
There are very little objective arguments as to why a convention would be better than another (by definition a convention is arbitrary), and even if there was, the absolute worse thing you can do is mix several conventions, because then you have 0 convention at all and never know what to expect.
At least C# tries to standardize; I've worked on several C++ codebases and I fail to see a common denominator: UpperCaseClassNames, lowerCaseClassNames, underscore_separated, tClassName, ENUMS_IN_UPPER, or not... it's rarely consistent, so the less you mix the better.

How can I find a list of methods of Array type in Swift? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm looking for a list of methods that I can use on Array in Swift.
For example you can run isEmpty on an array, but I couldn't find a list of all methods.
For exmaple I couldn't find global functions like find in the formal documentation
When you cmd-click a built-in function or type Xcode displays a generated file with the entire contents of the module to which that function or type belongs. In this case, if you cmd-click a Swift type (like String) or function (like find), you can see the declarations for the entire Swift built-in library.