Tag Info

Hot answers tagged

5

You should choose between init in declaration or constructor, not both. In a language that has a default constructor where you don't have to explicitly provide a constructor if the default is all you need, a declaration init may be fine. As soon as you need an explicit constructor with parameter, I tend to move everything to constructor(s), to ensure that ...


4

Addition of many elements to the end is O(m + logn), where m is the number of elements to be added. These operations would be O(n + m), and if m = n then they are almost as fast as addition to the end. In practice, they would be many orders of magnitude faster than if the user implemented them naively. However, for small numbers of elements, they would ...


2

Try a readonly variable. MSDN says this: The readonly keyword differs from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, although a ...


2

The interface should be as generic as possible. So, while this is an interface of Cars, if we assume that any car will be capable of having an owner, then the method for getting the owner should be inside the interface. However, any non-generic method, e.g. the method for taking the model of the Car's TV should not be inside the interface, since not all ...


2

Not so much. Maybe. The problem is that if Al from LA marks something with 1/1/2015 10AM and 7/1/2015 10AM, those will be different offsets from GMT. "What the user expects it to be" can get really dicey given our overly complex way of measuring times. Where at all possible, work using UTC (which may or may not be different from GMT depending on your ...


2

I have an object that has about 50 properties, Stop! Go - right now - and fix this. Of course you're going to run into functions that only use part of your object, when your object is doing everything under the sun. No object needs 50 independent properties. Certainly some of them can be organized into sub-objects. Those three that your function takes ...


1

The web server is saving the data, not the user, so it doesn't matter what the user's time is. The object should be saved with a timestamp in GMT (universal) time format. Save the user's GMT timezone offset, Then add that offset to the timestamp (which is in UTC) to present to the user, his own local time. For example, since I'm in CA, my ...


1

Customization is as simple or complex as introducing any other requirement. Each time you add a custom business rule or a business rule modification to your application, analyse how to make this rule visible or invisible, active or inactive, available or not available by some kind of run-time switch. Think of the customization step just as an extra, ...


1

OP is having this confusion because of poor naming. The reason OP asks this question is because OP has a confusion between the Repository Pattern and general object-oriented design. The repository object sits between the OOP design - say, a Car class, and the database. The "repository-object" relation shall not be confused with the ...


1

if space is not of concern and your application can afford to use as many space as you want, I'm thinking of 3-dimensional array (or to be more precise, 2-dimensional array of list) structure 2-dimensional array will represent the screen. Each pixel is an element in the array. Each location in array contains a pointer to a list of shape identifier e.g. ...


1

You can use Memory Cache. I use memory cache to cache data rarely changes or at the specific time. Here is example: public static T GetCache<T>(string key, Func<T> initializer) where T : new() { if (!MemoryCache.Default.Contains(key)) { try { T data = initializer(); AddData(key, data); return ...


1

If one thread calls Add, and another thread calls Contains, at exactly the same time, and everything is implemented correctly, then Contains will return either the value that was correct before calling Add, or the value that was correct after calling Add. That's the best that we can expect. If you can implement both the Add and the Contains method in a way ...



Only top voted, non community-wiki answers of a minimum length are eligible