>I have a habit of using code like this:
>
>
oMyObj = CreateObject("CoolClass")
>
>when I want to instantiate a class. However I have been seeing code snippets that are more like:
>
>
oMyObj = NewObject("CoolClass")
>
>When should I be using each?
The difference is in the second parameter of NewObject() - both function and method. The second parameter is the classlib (or .prg), so you don't have to Set Classlib To ... or Set Procedure To ... to have it available for Createobject(), you can explicitly say from which library you want the object to be created.
Both ways have their downsides - if you open all classlibs and procedure files at startup (as some frameworks do), you can go merrily with createobject() and never bother with the actual locations; this also means you'll have trouble locating the class when debugging. The other method requires you to know where your class is defined when you want to use it, and you don't have to open all classlibs and procedure files in advance, but then you have to know their names while writing, and if you move a class from one classlib to another, your code will break (while in the first case it won't).
There's also a weird thing about having all classlibs open - if you have a class of same name in several classlibs, and all of them are open, which one will get created is a matter of the order of opening the classlibs. I think it's "the last takes it all", but haven't used the other framework which worked that way for quite a while.