types

When to use unsigned values over signed ones?

So I hear a lot of opinions about this, and I wanted to see if there was anything resembling a consensus. When is it appropriate to use an unsigned variable over a signed one? What about in a for loop? for (unsigned int i = 0; i < someThing.length(); i++) { SomeThing var = someThing.at(i); // You get the idea. } As I said, I...

How can I determine the type of a blessed reference in Perl?

In Perl, an object is just a reference to any of the basic Perl data types that has been blessed into a particular class. When you use the ref() function on an unblessed reference, you are told what data type the reference points to. However, when you call ref() on a blessed reference, you are returned the name of the package that refe...

Haskell's algebraic data types

I'm trying to fully understand all of Haskell's concepts. In what ways are algebraic data types similar to generic types, e.g., in C# and Java? And how are they different? What's so algebraic about them anyway? I'm familiar with universal algebra and its rings and fields, but I only have a vague idea of how Haskell's types work. ...

How can I convert types in C++ ?

...

Why does this C code produce a double instead of a float?

celsius = (5.0/9.0) * (fahr-32.0); Is it just a development choice that the C developers decided upon or is there a reason to this? I believe a float is smaller than a double, so it might be to prevent overflows caused by not knowing what decimal format to use. Is that the reason, or am I overlooking something? ...

Is solving the halting problem easier than people think?

Although the general case is undecidable, many people still do solve problems that are equivilent well enough for day to day use. In cohen's phd thesis on computer viruses, he showed how virus scanning is equivilent to the halting problem, yet we have an entire industry based around this challenge. I also have seen microsoft's terminat...

Old style and new style classes in Python

What is the difference between old style and new style classes in Python? Is there ever a reason to use old-style classes these days? ...

Best Way to Unit Test a Website With Multiple User Types with PHPUnit

I'm starting to learn how to use PHPUnit to test the website I'm working on. The problem I'm running into is that I have five different user types defined and I need to be able to test every class with the different types. I currently have a user class and I would like to pass this to each function but I can't figure out how to pass th...

How to infer coercions?

I would like to know how to infer coercions (a.k.a. implicit conversions) during type inference. I am using the type inference scheme described in Top Quality Type Error Messages by Bastiaan Heeren, but I'd assume that the general idea is probably the same in all Hindley-Milner-esque approaches. It seems like coercion could be treated a...

Is there a common way to check in Python if an object is any function type?

I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so far is: isinstance(ob...

What is cool about generics, why use them?

I thought I'd offer this softball to whomever would like to hit it out of the park. What are generics, what are the advantages of generics, why, where, how should I use them? Please, keep it fairly basic. Thanks. ...

how to embed a true type font within a postscript file

I have a cross platform app and for my Linux and Mac versions it generates a postscript file for printing reports and then prints them with CUPS. It works for simple characters and images but I would like to have the ability to embed a true type font directly into the postscript file. Does anyone know how to do this?? Also I can encode ...

ASP.NET : How to detect file upload Mime type?

How do people usually detect mime type once file uploaded using asp.net? ...

What is the easier way to know if a type param implements an interface in c# 2.0?

For example, given a type param method i'm looking for something like the part in bold void MyMethod< T >() { if ( typeof(T).Implements( IMyInterface ) ) { //Do something else //Do something else } Anwers using C# 3.0 are also welcome, but first drop the .NET 2.0 ones please ;) ...

System.Convert.ToInt vs (int)

I noticed in another post, someone had done something like: double d = 3.1415; int i = Convert.ToInt32(Math.Floor(d)); Why did they use the convert function, rather than: double d = 3.1415; int i = (int)d; which has an implicit floor and convert. Also, more concerning, I noticed in some production code I was reading: double d = 3...

Implementing IntelliSense-like behavior in custom editors for domain-specific languages

I'm creating a DSL with a template-like editor, much like the rule systems in Alice. Users will be able to select relationships from a list as well as the objects to apply the relation to. These two lists should be filtered based on the acceptable types -- for instance, if the relationship is "greater than" then the available objects m...

What's the difference between 'int?' and 'int' in C#?

I am 90% sure I saw this answer on stackoverflow before, in fact I had never seen the "int?" syntax before seeing it here, but no matter how I search I can't find the previous post, and it's driving me crazy. It's possible that I've been eating the funny mushrooms by accident, but if I'm not, can someone please point out the previous po...

How can you add additional logic to type resolution at runtime?

Is there a generic way, without creating and managing your own CLR host, to take over locating and loading a type if that type is not found? The following is just an example. In your rush to be the first answer, don't suggest the new add-in framework or the MEF as a solution to my question. An example would be a sample with add-ins. ...

.NET SOAP Common types

Is there a way when creating web services to specify the types to use? Specifically, I want to be able to use the same type on both the client and server to reduce duplication of code. Over simplified example: public class Name { public string FirstName {get; set;} public string Surname { get; set; } pu...

.NET Integer vs Int16?

I have a questionable coding practice. When I need to iterate through a small list of items whose count limit is under 32000, I use Int16 for my i variable type instead of Integer. I do this because I assume using the int16 is more efficient than a full blown Integer. Am I wrong? Is there no effective performance difference (however ...