Assuming a method with the following signature
bool TryXxxx(object something, out int toReturn)
What is it acceptable for toReturn to be if TryXxxx returns false?
In that it's infered that toReturn should never be used if TryXxxx fails does it matter?
If toReturn was a nulable type, then it would make sense to return null. But int i...
I'm reading McConell's Code Complete, and he discusses using boolean variables to document your code. For example, instead of:
if((elementIndex < 0) || (MAX_ELEMENTS < elementIndex) ||
(elementIndex == lastElementIndex)){
...
}
He suggests:
finished = ((elementIndex < 0) || (MAX_ELEMENTS < elementIndex));
repeatedEntry = (...
If I have have some overloaded ostream operators, defined for library local objects, is its okay for them to go to std namespace? If I do not declare them in std namespace, then I must use using ns:: operator <<.
As a possible follow-up question, are there any operators which should go to standard or global namespace?
...
I'm working on a project where a mixture of C# (95%) and C++/CLI (5%) are used.
The namespace naming convention I'm aiming for is the good old Company.Technology.Etc.. This works perfectly fine for C#. Now, can I carry this across to C++ classes? I read here that compound namespaces aren't supported in C++.
Am I stuck with the clumsy
...
Exceptions are wonderful things, but I sometimes worry that I throw too many. Consider this example:
Class User {
public function User(user){
// Query database for user data
if(!user) throw new ExistenceException('User not found');
}
}
I'd argue that it makes as much sense to simply return false (or set all us...
Almost any mature program that involves text implements "double click to select the word" and, in some cases, "triple click to select additional stuff like an entire line" as a feature. I find these features useful but they are often inconsistent between programs.
Example - some programs' double clicks do not select the ending space aft...
I'm developing a Rails application and within that application I developed a Rake task that will read entries from a file and store them into the DB. Producing the code was no problem, but I'd like to know, where do I place the file that is read? Is there a convention for that, if yes, what is it?
I know I could have used the seed.rb fi...
Below is an example of how I currently use automapping overrides to set up a my db representation of inheritance. It gets the job done functionality wise BUT by using some internal default values. For example, the discriminator column name winds up being the literal value 'discriminator' instead of "ActivityType, and the discriminator va...
In Java/C++, for example, do you casually say that 'a' is the first character of "abc", or the zeroth?
Do people say both and it's always going to be ambiguous, or is there an actual convention?
A quote from wikipedia on Zeroth article:
In computer science, array references also often start at 0, so computer programmers might use...
Hi, I am trying to create a fluent Nhibernate automap convention for all the modifiedDate property of my application where it should set the value to get the current date during UPDATE. I am trying the following and its not working. I want the SQL server to update the date. Please advice.
public class ModifiedDateVersionConvention : IVe...
I have generally always used some sort of Hungarian Notation for my field names in my tables e.g.
#Table Users
u_id, u_name, u_email etc...
#Posts
p_id, p_u_id, p_title, p_content etc...
But I have recently been told that this isn't best practice. Is there a more standard way of doing this? I haven't really liked just using the field...
I am reviewing another developer's code and he has written a lot of code for class level variables that is similar to the following:
/// <summary>
/// how often to check for messages
/// </summary>
private int CheckForMessagesMilliSeconds { get; set; }
/// <summary>
/// application path
/// </summary>
pr...
Hi,
I want to use schemaExport to generate my Database. So, I would like some help as one of my table
needs to have a non-clustered index on one column.
Is there any way I can use the IIndexConvention to implement it?
I could use a custom attribute to distinguee the property and then apply the convention for example.
Many thanks.
...
Is there a preferred (not ugly) way of outputting a list length as a string? Currently I am nesting function calls like so:
print "Length: %s" % str(len(self.listOfThings))
This seems like a hack solution, is there a more graceful way of achieving the same result?
...
Generally speaking, creating a fluid API is something that makes all programmers happy; Both for the creators who write the interface, and the consumers who program against it. Looking beyond conventions, why is it that we prefix all our getters with the word "get". Omitting it usually results in a more fluid, easy to read set of instruc...
In some sample codes there are methods and classes declared WITHIN other methods and/or classes.
I've never heard/read about this. What effect does this kind of programming have? Wouldn't it be better to write down classes in a seperate file and methods side by side and not within each other (like every book tells you)? What are the adv...
My class with an event:
public class WindowModel
{
public delegate void WindowChangedHandler(object source, WindowTypeEventArgs e);
public event WindowChangedHandler WindowChanged;
public void GotoWindow(WindowType windowType)
{
this.currentWindow = windowType;
this.WindowChanged.Invoke(this, new Windo...
I am in a team developing a web-based university portal, which will be based on Django. We are still in the exploratory stages, and I am trying to find the best way to lay the project/development environment out.
My initial idea is to develop the system as a Django "app", which contains sub-applications to separate out the different par...
Yesterday, I was designing a Java class which I wanted to be initalized with Lists of various generic types:
TheClass(List<String> list) {
...
}
TheClass(List<OtherType> list) {
...
}
This will not compile, as the constructors have the same erasure.
I just went with factory methods differentiated by their names instead:
publi...
If I do
double d = 34.56;
int i = (int)d;
Am I not "downcasting"?
OR
Is this term only used in terms of classes and objects?
I am confused because in this case we are "downcasting" from a bigger double to a smaller int, but in case of classes, we "downcast" from a smaller base class to a bigger derived class.
Aren't these two c...