Ha yes! sorry didn't mean to come across as a bit of a code nazi
. I saw the keywords tips/comments/suggestions in jimmers last post and I went into Code Review mode. Replace the words 'should' and 'NEVER' with 'could' and 'AVOID if possible' respectively in my previous post. Also please note that I didn't compile it, just eyeballed it and noticed that your static wasn't defined.
Evil isn't always a bad thing, as I said I have used global variables, and will continue to do so! void*
are my posion. I find them extrmamly useful but extrmeley dangerous, use them all the time in my own code but would get lynched at work... and for a very good reason. As foet says pretty much most c++ features and laguange is there to aid in design, implementation and maintainability (the latter of which I do think is lacking in the industry, or at least the places I've worked!)...otherwise we might as well all just write in assembly and be done with it. Just because you can use non-safe types and directly access low-level stuff in C++, does that mean you should if there is another way which fits more in line with the way the tools are designed to be used?. However if it starts to hinder readability, then it should be questioned... why is something designed to aid work, hindering it. Right tool for the right job I believe is the phrase (this should also be applied when I see those boring arguments about which is better C or C++...they are different tools, to be used differently and within different environments/contexts, probably for different reasons)
On using namespace
, yes smaller personal projects (in which you are the architect, code monkey, tester...and probably user) it's perfectly fine and should be used as a tool to help/speed coding (it could be argued that this is the same with typedefs
). This is definately the case in source files, but in a header with large projects it can be horrible to deal with... well the person who wrote it probably wouldn't think so, but later maintainers may well cry (especially if they have to write implementations/drivers which use pretty the mush the sames types (naming wise)).... same with void*
, if I came across code with void*
I would not be happy (other than my own ofcourse!). With you in control of your own project this is all moot.
As has been said, at the end of the day use what ever convention you are most comfortable with as this will probably allow you to be most productive. There are very few conventions/idioms that I would recommend against tbh...
spiroyster wrote:global variables are considered evil in c++, not c (In c there are pretty much an absolute!) for a number of reasons, mainly they imply bad/non-existant oo design.
Took this part of your comments to heart and pulled 'The Gang of Four' off my shelf for the first time since uni (the bill says I bought it in 1997...). Have now re-implemented the FTP class as a Singleton. As you suggested, using a more OO idiom fixed the static/non-static linker thing in one fell swoop. Will refactor the rest of my code to be more OO in design.
Thanks again for taking time to give me your feedback and suggestions. Much appreciated
No problem, glad its working for you! it makes a nice change to look at something else for a change. Yes singletons are great.... singletons, stack objects and cheshire cat are probably my most used patterns (cheshire cat might seem detrimental, but on larger code bases it can reduced compilation times drastically, which on some of the systems I work with can be the difference between an hour and 20 min for an entire rebuild). They are all there to help, and avoid bitting you in the XXXX (<- well put!)