strong-typing

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

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

Enforce strong type checking in C (type strictness for typedefs)

Is there a way to enforce explicit cast for typedefs of the same type? I've to deal with utf8 and sometimes I get confused with the indices for the character count and the byte count. So it be nice to have some typedefs: typedef unsigned int char_idx_t; typedef unsigned int byte_idx_t; With the addition that you need an explicit cast...

Java Generics - difficulty enforcing strong type checking

Here's my code: public class Sequence<T> { protected List<T> sequence = new ArrayList<T>(); public Matrix<OrderedPair<T, ?>> createCartesianProduct(Sequence<?> secondSequence) { Matrix<OrderedPair<T, ?>> result = new Matrix<OrderedPair<T, ?>>(); for (int rowIndex = 0; rowIndex < sequence.size(); rowIndex++) { S...

Do you encapsulate scalars?

I find myself defining classes like: struct AngleSize { explicit AngleSize(double radians) : size(radians) {} double size; }; This has a bunch of advantages over storing anglesizes as plain doubles. Advantage 1, it makes it possible to define these 2 distinct constructors: Vec2::Vec2(double x, double y); Vec2::Vec2(double l...

Strongly typed calls into web.config without duplicating the property names?

I searched here for the answer. I'm sorry if this has been asked before (as I suspect it has). Summary: How can I have strongly typed calls into my web.config without duplicating the property names? Details: In my code, I try to minimize string usage, and I don't like defining something twice. Complementing both of these wonts is m...

Is there a dream language that merges the benefits of dynamic and strong typing?

I would be interested to learn a language that handles objects internally as hashtables (like JavaScript) but could wrap them with strong types to offer the benefits of code completion/intellisense in design time. Here is how I wish this dream language to work: public class Lion { public void Roar() { Console.WriteLine("Aaarrgghh");} ...

Why can't I pull a ushort from a System.Object and then cast it as a uint? (C#)

I'm manipulating the items in a list that's a System.Management.ManagementObjectCollection. Each of these items is a System.Management.ManagementObject which contains properties indexed by string. See: foreach (ManagementObject queryObj in searcher.Get()) { string osversion = (string)queryObj["Version"]; string os = (string)quer...

Will PHP become a full fledged statically typed OOP language in the near future or ever?

I was wondering whether it is the intent of the development team of the PHP language to make it into a full fledged statically typed OOP language at some point. Any ideas about this? Edit: To add to that: Will this be a performance hit for a non-compiled language? Or are there similar purpose scripting languages that have these capabili...

Functions accepting C/C++ array types

It seems like g++ ignores difference in array sizes when passing arrays as arguments. I.e., the following compiles with no warnings even with -Wall. void getarray(int a[500]) { a[0] = 1; } int main() { int aaa[100]; getarray(aaa); } Now, I understand the underlying model of passing a pointer and obviously I could just def...

Strong Typing a property name in .NET

Say I have a class with one property Public Class MyClass Public Property MyItem() as Object .... End Property End Class I have to pass the name of the property to a function call. (Please don't ask why it should be done this way, its a third party framework). For example SomeFunc("MyItem") But what I would like to do i...

Strong vs weak typing

The way I understand it, the following is allowed in PHP because it's a weakly-typed language. $var = 'Hello'; $var = 5; I just installed a Windows version of Python 2.6 and I was expecting it NOT to let me change type just like that, but the Python equivalent of the above code works just like in PHP yikes! >>> var = "Hello" >>> type...

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

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? "Ints don't have any member data" Yes they do, they have 32 bits, or whatever....

Static/Dynamic vs Strong/Weak

I see these terms banded 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. Differen...

C#: How to find the default value for a run-time Type?

So given a static type in your code you can do var defaultMyTypeVal = default(MyType); How would you do the same thing given a variable of Type so you can use it during runtime? In other words how do I implement the following method without a bunch of if statements or using Generics (because I will not know the type I'm passing into ...

Best way to create a strongly typed wrapper for Dictionary<string, string>

I have a Dictionary containing configuration values for other classes (tasks which will be executed periodically performing assorted specialized logic) which are persisted in a database and then passed back in at execution time. I want to create a strongly typed wrapper for this Dictionary, both to allow easy access to the values and to...

How do I strongly type criteria when using NHibernate's CreateCriteria method?

I'm currently using NHibernate, for the first time, with Fluent NHibernate. I've gotten everything setup nicely, however now I've come to actual doing some data retrieval, it seems to have fallen short. I was expecting NHibernate, to allow me to do something like: session.CreateCriteria<TblDocket>() .Add(Restrictions.Eq(x=> x.Docke...

Strongly-typed integers

As a thought experiment on a hobby project, I've been thinking of a way to ensure that this sort of subtle bug/typo doesn’t happen: public void MyMethod(int useCaseId) { // Do something with the useCaseId } public void SomeOtherMethod() { int userId = 12; int useCaseId = 15; MyMethod(userId); // Ooops! Used the wrong va...

Strict vs loose typing when overriding a method

I have a class called AddressCard from an example in "Programming in Objective C", and I'm implementing a isEqual: method. The signature of this method in NSObject uses loose typing for the parameter: - (BOOL)isEqual:(id)anObject OTOH, the sample code in the book uses strict typing: - (BOOL) isEqual:(AddressCard *) aCard I'm not s...