collapse collapse

* Who's Online

  • Dot Guests: 40
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Author Topic: Re: Challenge: Celestialkey's Submission  (Read 5091 times)

0 Members and 1 Guest are viewing this topic.

Offline 0xDEAD10CC

  • Newbie
  • *
  • Posts: 21
  • Reputation 0
  • Gender: Male
  • void of_space();
    • View Profile
Re: Challenge: Celestialkey's Submission
« on: April 13, 2014, 02:47:50 am »
This should never be within a header file ever:
Code: [Select]
using namespace std;
I suspected this was what you were doing when I didn't see any namespace specifier explicitly within the cpp source and any using directives... The reason is because now if somebody goes to use your header, certain unintentional identifier ambiguities may exist, even if his/her code was careful to avoid them. Irregardless, writing that anywhere in your code essentially defeats the whole point of namespaces.

http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c
http://www.cplusplus.com/forum/beginner/25538/

Another thing, with C++ you hardly should ever be required to use global variables:

Code: [Select]
CFileSystem f;

char* file;

I also think that the use of third party libraries/headers is almost cheating, especially since this wasn't specified within the guidelines in the first post as to whether or not they could be used. Otherwise, perhaps helper libraries can be used (BOOST?), and there must be in place, some form of limitations as to what kinds of libraries you can use, based on what they do.

This challenge is really as trivial as understanding how to write a table of contents (to the header metadata of the output file) and the file binary data in the structure specified within that structure header to a single file... Separators if naive, but this would be less efficient IMO.
« Last Edit: April 13, 2014, 02:55:29 am by 0xDEAD10CC »
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Re: Challenge: Celestialkey's Submission
« Reply #1 on: April 13, 2014, 11:14:59 am »
This should never be within a header file ever:
Code: [Select]
using namespace std;
I suspected this was what you were doing when I didn't see any namespace specifier explicitly within the cpp source and any using directives... The reason is because now if somebody goes to use your header, certain unintentional identifier ambiguities may exist, even if his/her code was careful to avoid them. Irregardless, writing that anywhere in your code essentially defeats the whole point of namespaces.

http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c
http://www.cplusplus.com/forum/beginner/25538/
Artifacts from testing. Also, I don't believe any sensible person would create functions that conflict with the std namespace. I'll fix this one since it makes sense and I agree with it.

Another thing, with C++ you hardly should ever be required to use global variables:

Code: [Select]
CFileSystem f;

char* file;
[/code]
It was a quick and dirty demonstration of the class' use. No need for setting anything more complicated up. There is nothing wrong with using globals anyhow with small programs. It only comes into play when you use larger applications and your code starts looking like spaghetti code. In term of 'good' and 'bad', programming is still suffering from all the pitfalls it has had in the past and there is plenty of programming that goes on everyday with professions that I, and many others, consider bad practice regardless of if they use globals. I feel like this one was nitpicking.

I also think that the use of third party libraries/headers is almost cheating, especially since this wasn't specified within the guidelines in the first post as to whether or not they could be used. Otherwise, perhaps helper libraries can be used (BOOST?), and there must be in place, some form of limitations as to what kinds of libraries you can use, based on what they do.

This challenge is really as trivial as understanding how to write a table of contents (to the header metadata of the output file) and the file binary data in the structure specified within that structure header to a single file... Separators if naive, but this would be less efficient IMO.
I only use the derint header to traverse directories. This action is a LOT easier in Linux then it is in windows. Windows has no true functions to traverse directories, it only has very basic and clunky methods which would cause the code to become close to unreadable. ALL file input and output is done using the native OS, only directory traversal is using the derint header. If you were to use boost, it would take the majority the functions over since boost gives you plenty of alternatives for traversing, reading, and writing to files.

All in all, the main thing to remember here is that this is a response to a specific challenge. No need for proper etiquette when your writing code for a specific 1 goal purpose.
Thanks for your input otherwise.
« Last Edit: April 13, 2014, 11:23:17 am by Celestialkey »
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Re: Challenge: Celestialkey's Submission
« Reply #2 on: April 13, 2014, 12:31:27 pm »

Another thing, with C++ you hardly should ever be required to use global variables:

Code: [Select]
CFileSystem f;

char* file;

I believe this to be one of those things that people say in a classroom but people who develop real projects don't follow (like using smart pointers).

Examples:
Valve SDK: https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/public/disp_powerinfo.cpp
Doom 3: https://github.com/TTimo/doom3.gpl/blob/master/neo/game/Game_local.cpp and https://github.com/TTimo/doom3.gpl/blob/master/neo/game/Pvs.cpp

(There are some who think Doom 3 sucks, however, critics disagree and the simple fact they sold over 3.5 million copies says something about if people liked the game...but I digress).

If you think they are bad programmers - feel free to phone John Carmack or Gabe Newell and tell them how bad of a programmer you think they are. Granted, people like John Carmack have had tons more experience than most people, however it really boils down a programming style as I'm sure they have been programming like that since they started. Or perhaps it was their respective teams, however, I'm sure they have code reviews and if someone really disagreed with that practice it wouldn't have made production code.

Everyone has their own style, wither it's right or wrong is debatable but I think this is the wrong time/place to do that. However, I think this reddit comment proves that point. Pointing out functional problems (such as issues where the code would never compile) in code sure, not style problems. We could go back and forth on what's right and wrong in fact I have read pages and pages on google groups about people discussing STL style (I believe it was on shared_ptr usage and implementation). Just remember there will always be people out there who are making 2-3 times as much as you ever will writing worse code.

Here is an example: I believe the auto keyword was a horrible addition to the C++ language - however - enough people on the C++ teams thought otherwise. One of the developers of Java thinks the same way that I do and rejected an auto keyword into the Java language. In my opinion I think people shouldn't use it - but it's like the goto keyword, there is nothing wrong in using or not using it. Granted the use of the goto keyword use in C++ is usually not needed but that doesn't mean it's a deprecated feature or an unsupported feature. If it works - great, however, I think there is a good quote that shows up on celestialcoding that goes something like this "Always code as if the person who will maintain your code is a maniac serial killer that knows where you live".

I also think that the use of third party libraries/headers is almost cheating, especially since this wasn't specified within the guidelines in the first post as to whether or not they could be used. Otherwise, perhaps helper libraries can be used (BOOST?), and there must be in place, some form of limitations as to what kinds of libraries you can use, based on what they do.

I'm not seeing third party libraries really? The only one that isn't natively on Windows is dirent.h and you can grab a copy for Windows here: http://www.softagalleria.net/dirent.php (looks like MIT style license even). dirent.h is part of the POSIX standard so it's not Celestialkey's fault if Microsoft decided not to port that.

This challenge is really as trivial as understanding how to write a table of contents (to the header metadata of the output file) and the file binary data in the structure specified within that structure header to a single file... Separators if naive, but this would be less efficient IMO.

After teaching a class - you make think it's trivial but there are many people out there who would struggle with this. There are people who spend 9+ hours on a programming assignment. I know students who worked several hours on a Java threading assignment even though most of the sample code was given to them and they just had to add about 4 lines of code to get it working.

(I have actually seen people on reddit say that they should change majors if they are struggling that bad. Just because you struggle with programming doesn't mean you can't be an awesome network guy, or Windows/Linux admin, or exchange admin, or....again I digress).

Edit: Celestialkey - perhaps you should cut these posts out into their own thread so they don't clutter this original thread?
« Last Edit: April 13, 2014, 12:51:12 pm by Nathan »
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline 0xDEAD10CC

  • Newbie
  • *
  • Posts: 21
  • Reputation 0
  • Gender: Male
  • void of_space();
    • View Profile
Re: Re: Challenge: Celestialkey's Submission
« Reply #3 on: April 13, 2014, 09:10:26 pm »
This should never be within a header file ever:
Code: [Select]
using namespace std;
I suspected this was what you were doing when I didn't see any namespace specifier explicitly within the cpp source and any using directives... The reason is because now if somebody goes to use your header, certain unintentional identifier ambiguities may exist, even if his/her code was careful to avoid them. Irregardless, writing that anywhere in your code essentially defeats the whole point of namespaces.

http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c
http://www.cplusplus.com/forum/beginner/25538/
Artifacts from testing. Also, I don't believe any sensible person would create functions that conflict with the std namespace. I'll fix this one since it makes sense and I agree with it.

Another thing, with C++ you hardly should ever be required to use global variables:

Code: [Select]
CFileSystem f;

char* file;
[/code]
It was a quick and dirty demonstration of the class' use. No need for setting anything more complicated up. There is nothing wrong with using globals anyhow with small programs. It only comes into play when you use larger applications and your code starts looking like spaghetti code. In term of 'good' and 'bad', programming is still suffering from all the pitfalls it has had in the past and there is plenty of programming that goes on everyday with professions that I, and many others, consider bad practice regardless of if they use globals. I feel like this one was nitpicking.

I also think that the use of third party libraries/headers is almost cheating, especially since this wasn't specified within the guidelines in the first post as to whether or not they could be used. Otherwise, perhaps helper libraries can be used (BOOST?), and there must be in place, some form of limitations as to what kinds of libraries you can use, based on what they do.

This challenge is really as trivial as understanding how to write a table of contents (to the header metadata of the output file) and the file binary data in the structure specified within that structure header to a single file... Separators if naive, but this would be less efficient IMO.
I only use the derint header to traverse directories. This action is a LOT easier in Linux then it is in windows. Windows has no true functions to traverse directories, it only has very basic and clunky methods which would cause the code to become close to unreadable. ALL file input and output is done using the native OS, only directory traversal is using the derint header. If you were to use boost, it would take the majority the functions over since boost gives you plenty of alternatives for traversing, reading, and writing to files.

All in all, the main thing to remember here is that this is a response to a specific challenge. No need for proper etiquette when your writing code for a specific 1 goal purpose.
Thanks for your input otherwise.

Sometimes that's unavoidable (For the reason that I don't believe that any programmer has remembered all of what the STL contains, and newer standards of the language are always adding to it; I certainly can't remember the entire STL). I doubt any programmer would be willing to check what exists in those namespaces to avoid any/all possibility of conflicts. If they do, they have too much time on their hands and are wasting valuable development time for no reason; It could be avoided simply by just neglecting 'using namespace std;'. The verbosity of the namespace specifier also helps when reading the code to know where something came from.

Avoiding globals also eases the debugging process, aside from taking advantage of proper function and class usage in regards with scope and object lifetime. Small programs can become large ones, I wouldn't consider this submission small though... There's a fair bit of code here when you look at all the code in the few files. IMO it's best to develop and use good practices regardless of the size of the project.

I understand this is just a challenge, but I still don't see why it should be reason to write spaghetti/scrambled/half-motivated/{insert-programmer-specific-term-here} code. I'd be willing to be that Celestial is better than this (I don't have my doubts), I figured I'd just point these things out.

John Carmack is a decent programmer, but by all means, not a world class genius in pure programming terms. He is with graphics, that's his thing, and that's why he's successful in the gaming industry. He has ideas, he knows how the GPU renders things, and how various monitors affect the output display... This doesn't mean he writes perfect code (and nor does it mean he writes poor code or that I'm saying he's not a good programmer here). He also has older programming habits that don't apply as much with newer language standards and compilers. People just follow his ideas and style because of the impression he's made through games like Doom3 and Quake.

This wasn't about game programming or smart pointers, I'm simply stating proper semantics for the way C++ was designed to be used. C++ is not C, yet there are MANY MANY programmers that seem to think so, by using pointers and overusing #define macros where there is no need, among many other things. Those defines make things harder to debug and const usually satisfies the requirement not to use them 80 to 90% of the time. C++11 also has constexpr, which gives you more flexibility over other things.

Programming style is big, but that doesn't mean all standards and properness go out the window because your style seemingly overrules it, although along with programming style, consistency is just as important. There are still guidelines, and although they are nice, I will agree with anyone who says sometimes they need to be bent in project specific circumstances. :)

I also agree that people can struggle with programming, but that still doesn't quite mean they can (or for a better term *should*) avoid good programming practices. Those kinds of people can STILL learn successfully regardless of how long it takes them to learn something.

I hope this makes things clear on my behalf. At the end of the day, programming challenges are about learning correct? So why not show other 'contestants' code that they can look at and learn from? Surely the worst thing would be to have someone look at a snippet of code and think it's gold when really it's a bunch of copper (for lack of a better analogy)?

If you KNOW that you could write something better, then why are you posting/submitting the code? And again, since you guys always seem to think I'm in offensive mode here, that is not an insult, that is simply a statement being made to make my reasoning clear here.

If you're the greatest programmer in the world, and you make a challenge, post half-assed code, then I highly doubt that you are learning as much as you could take from your own programming challenge, and furthermore, not giving others the best chance to learn from a good example.

Once in a while, be open-minded and look at the purpose behind my post before judging me as a member through the tone derived from the context my words are put in. :) I just put things out there, I don't pamper other programmers, it's their own incentive and initiative that should allow them to take my feedback for what it is.

Cheers
« Last Edit: April 13, 2014, 09:24:10 pm by 0xDEAD10CC »
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Re: Challenge: Celestialkey's Submission
« Reply #4 on: April 13, 2014, 10:56:44 pm »
You will find no disagreement from me that avoiding the usage of global variables leads to better design in favor of using classes or even structs. This has been proven, there is no argument here. Not using "using namespace" in headers - as well there are enough solid reasons not to do that.

However, I have seen cases where using global variables makes development easier. I don't know if you use or have used Python/Django but it really does encourage, in my opinion at least, bad programming styles (now PHP is the equivalent of putting a loaded gun in your hands, Django in my mind tells you to look down the barrel). I even tried to ask how to introduce more sane site development using classes and was basically shot down because I was trying to introduce my own functionality into the framework (wait, what?). In any case, Django is really function based so a large site becomes a tangled mess and lots of grepping - but one thing I have noticed from one developer is that in order to avoid global variables is to pass a variable to every function. If I was writing the same thing I would have just stuck with a global variable - simply because it would be easier to use throughout the code as Django is already a mess I would rather not make it even harder. In C I might still, but in C++ I would just make it a class member (well maybe in C I would use a struct with function pointers that have a parameter as the variable inside of the struct - it's really the same thing except that it's self contained rather than a "global" variable).

I did stick with my implementation and if I wanted a "global" variable type all I did was add it as a variable in the class. And since the controllers inherit from a base class it just made sense.

(Aside comment: Django is also written by the same people who think that they shouldn't provide support for Unixtime stamps)

I honestly think that part of the problem is the sheer size of the language - C++ has become this ginormous monolithic beast that whenever someone posts some code the immediate reaction is that the code must be perfect. The question is what is perfect? C++ textbook style? MFC style? Qt style? If the textbook styles/Stroustrup is right - then why are frameworks that abuse the standard styles like Qt so popular? Surely, if that style was so bad people would refuse to use their product no?

We saw this ideology with the Debian random number bug. They commented out code simply because a tool told them it was bad.

You know I actually smiled a little bit when you mentioned STL - this is yet another never ending argument with C++ opinions - is it the C++ standard library or STL? I know what you meant, the problem is that others get so hung up on little insignificant things like this.

Quote from: 0xDEAD10CC
Surely the worst thing would be to have someone look at a snippet of code and think it's gold when really it's a bunch of copper (for lack of a better analogy)?

Hahaha - I call these people stackoverflow coders. Simply because their programming ability extends to be able to only copy/paste snippets of code from stackoverflow. The worst part is I do use stackoverflow from time to time (ignoring the fact that stackoverflow uses a confusing license for the posted code) and some of the code I've seen is sometimes subpar.

Quote from: 0xDEAD10CC
Once in a while, be open-minded and look at the purpose behind my post before judging me as a member through the tone derived from the context my words are put in. :)

For me it's not just you personally - it's just I've read stuff like this over and over and over again that in my mind I've developed this bias/predisposition toward other C++ developers. And it's not just C++ developers - I also have this bias toward Django developers as well for the same reasons.

Now, I don't claim to be a C++ expert but I just grow tired of reading all the bashing and fallacious arguments, know what I mean? Perhaps I'm just not thick skinned enough - but personally I would rather read something that's like "hey, I like what you did but I think doing this would be better" rather than "This really does suck wow.". To be honest if someone I just meet talked to me like that - I would be put off a little bit. The problem being is that text can't deliver emotion so it's hard to tell if it's like a "friendly" criticism or just someone trying to be a jerk/troll. I'm not saying that's you - I'm just saying from what I've read. My two cents.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline 0xDEAD10CC

  • Newbie
  • *
  • Posts: 21
  • Reputation 0
  • Gender: Male
  • void of_space();
    • View Profile
Re: Challenge: Celestialkey's Submission
« Reply #5 on: April 19, 2014, 10:30:31 pm »
I will surely try my best to enlighten the tone that comes across in future posts. Sorry for the bad impression firsthand. It was never my initial intention. :)
[ Assembly / C++ / .NET / Haskell / J Programmer ]

 

Donate


* Search


* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]


Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 pm]