Internal typedefs in C++ – good style or bad style?

Something I have found myself doing often lately is declaring typedefs relevant to a particular class inside that class, i.e. class Lorem { typedef boost::shared_ptr<Lorem> ptr; typedef std::vector<Lorem::ptr> vector; // // … // }; These types are then used elsewhere in the code: Lorem::vector lorems; Lorem::ptr lorem( new Lorem() ); lorems.push_back( lorem ); Reasons I … Read more

Check if a string contains an element from a list (of strings)

For the following block of code: For I = 0 To listOfStrings.Count – 1 If myString.Contains(lstOfStrings.Item(I)) Then Return True End If Next Return False The output is: Case 1: myString: C:\Files\myfile.doc listOfString: C:\Files\, C:\Files2\ Result: True Case 2: myString: C:\Files3\myfile.doc listOfString: C:\Files\, C:\Files2\ Result: False The list (listOfStrings) may contain several items (minimum 20) and … Read more

codestyle; put javadoc before or after annotation?

I know that it isn’t the most vital of issues, but I just realised that I can put the javadoc comment block before or after the annotation. What would we want to adopt as a coding standard? /** * This is a javadoc comment before the annotation */ @Component public class MyClass { @Autowired /** … Read more

.toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])?

Assuming I have an ArrayList ArrayList<MyClass> myList; And I want to call toArray, is there a performance reason to use MyClass[] arr = myList.toArray(new MyClass[myList.size()]); over MyClass[] arr = myList.toArray(new MyClass[0]); ? I prefer the second style, since it’s less verbose, and I assumed that the compiler will make sure the empty array doesn’t really … Read more