Thread: Website updated (lightatdawn.cprogramming.com)

  1. #1

    Website updated (lightatdawn.cprogramming.com)

    I was just recently trapped at home for several hours. My only computer access was to a dusty P133 found in my closet. Armed with Notepad and a disk, I wrote a bunch of new tutorials as I had nothing better to do. Couldnt get on my system with the compilers and internet as it was rendering a rather long animated sequence for quite some time...

    So anyhow, aside from being rather proud that my Handled Doubly Linked List tutorial was written perfectly in Notepad and compiled without a single error when I eventually was able to test it, I've been updating my page. The new concepts section was made with the idea that I (and others) could refer people to answers that are asked repeatedly instead of continually answering them. New:

    Arrays (as strings, lookup tables, and multi-dimensional)
    Pointers (including memory allocation/deallocation)
    Structs explained (including allocating, arrays of, etc)
    Function Overloading
    Classes
    Linked Lists (Single, Double, and a specialised Handled List. Also includes brief templating example)

    Have a look. Tell me if I screwed up somewhere and somehow didnt notice. (Dont be too hard on me if I did. I didn't even have syntax highlighting let alone a compiler or help database for any of it...)
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Had a quick glance. Looks good!

    Only one point. You have C++ Builder down as a win32 only compiler. I understand that from version 6 onwards you can compile for Linux. Although I've never used it, I'm still using version 5.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    on the command page why recommend gets()?
    on the development page why recommend #define instead of const int ?
    had a quick spin thru most of the code. Bit worried about your assignment operator in the op overloading section. No check for self assignment. doesnt return *this either.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    >>on the command page why recommend gets()?

    Because its simple? Honestly, I dont use any of those input functions. But, hey, you've got to start somewhere... What do you recomend over gets? And dont say cin because we all know what I think about it...


    >>on the development page why recommend #define instead of const int ?

    Hard to answer this one. I've always used defines. I like macros over inlined functions in a lot of cases. Its really kind of the difference between why use classes over structs; preference. Is there a reason that constants would be superior? I cant think of [a good] one.

    >>Bit worried about your assignment operator in the op overloading section. No check for self assignment. doesnt return *this either.

    I'll have a look at that sometime tonight. As the little blurb at the top notes, I ran out of time on that one and just took some existing code and hacked it down to size. That assignment operator doesnt even exist in the total package but I'd overloaded so many assignment functions to perform various tasks (from strings, to character values, to conversion from integer to string, etc) that I just threw that in. I promise to fix and upload a better version before tomorrow.


    >>You have C++ Builder down as a win32 only compiler.

    I'll look into that. I have to admit to writting that page directly off the top of my head. I own all those compilers so I just spat out what I knew about them. I'll do a little research and update it.

    Thanks for the input guys.

    P.S. Thoughts on the setup of the examples? Are any notably confusing or have I over explained anything to death? I want them to be explained in enough depth that someone without any grasp of that concept can be pointed to the page and learn.

    Peace
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What do you recomend over gets?
    Something safe? Like fgets or getline. And fgets really isn't that much more complex than gets:

    fgets ( array, sizeof array, stdin );

    >Its really kind of the difference between why use classes over structs; preference.
    Not really, while the define directive does have its uses, in C++ those uses are very specialized. For example, you want a named constant integer, which would you use in C++?

    #define NAME 10
    or
    const int NAME = 10;

    Think of it this way, which one will the compiler perform type checking on? C++ features will almost always cancel out the need for the define directive. The only valid use for #define that C++ has no replacement is inclusion guards and other such conditional compilation.

    >have I over explained anything to death?
    Yes, if I see full pages of comments with no code it gets boring and can be confusing if you forget where you were in the code. I prefer to use a literate programming design where I show several relevant lines and explain them, then move on to the next few lines. That keeps the explanation as close to the corresponding code as possible and spaces out code with natural text so you don't have to move through reams of either code or comments.

    -Prelude
    My best code is written with the delete key.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Hard to answer this one. I've always used defines. I like macros over inlined functions in a lot of cases. Its really kind of the difference between why use classes over structs; preference. Is there a reason that constants would be superior? I cant think of [a good] one.
    use const & inline......

    #define MAX(a,b)((a) > (b) ? (a) : (b))

    Fine until you do something like pass a x++ to that macro....also the macro isnt type safe......

    Also

    Code:
    int main(){
    
    	#define X 10
    	
    	const int Y = 10;
    
    	int a = X;
    
    	int b = Y;
    	
    	return 0;
    
    }
    In most compilers, the assignment of a and b will be the same (with regard to the ASM code - 1 mov using a literal value), but Y will be seen my the debugger as a variable and shown as such....X will be stripped away by the preprocessor...just a little extra clarity for debugging..and again, types are enforced...no runtime penalty...so why not use them ?.....

    >>on the command page why recommend gets()?

    Because its simple? Honestly, I dont use any of those input functions. But, hey, you've got to start somewhere... What do you recomend over gets? And dont say cin because we all know what I think about it...
    fread() on the stdin?....

    Also, I sont see your concern on cout...let alone cin??? I mean....how fast can a user type that they are held back by these methods??? I cant imagine someone on today's pcs sat there waiting for cin to process the data.......also...cout???....you only have a fixed area to print out to, and you can only print as fast as people can read.......

    Just my 2c....

    <edit> AW nuts!...Prelude beat me....to slow typing....goddam cin!!!... </edit>

    Cool effort though.....

  7. #7
    Thanks for all the feedback guys (and gals ). I'll be changing gets to probably fgets. I'm going to fess up on something: I just used the first function that popped to mind for that one. I havent used any sort of paused-execution _anything_ in so long I'd practically forgotten what header it used. I guess thats what too much DirectX will do to you; You start to think quite differently about program flow.

    MACROS: I dont use any macros in any of the examples. I understand that they can be highly problematic, especially to the inexperienced. I'm not about to stop personally, though. I'm well aware of what I'm doing with them and use them to my convenience. Not sure I'd trust another programmer with some of it...

    const vs define: [Both] your arguments for const have caused me to reconsider. Its not something I've ever really thought about before. I've always used #define (since way back-in-the-day and all that). Since I've never encountered a bump on the road, I never thought twice about it. I'll make the changes in the examples, and likely try changing my own personal ways... But macros ain't leavin!

    >>if I see full pages of comments with no code it gets boring

    Yes, but I'm assuming that since someone is there, they're not there to be entertained, they're there to learn. Better to overexplain and bore than miss relevant data and confuse. But I'll see what I can do to shorten my chronic long windedness.

    I'd like to say updates by tonight but I'm really really busy so maybe not...

    Thanks for taking the time.

    Anyone else have any suggestions to make the code/examples easier to learn from?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  8. #8

  9. #9
    Wow, holy crap! A few is an understatement. Looks like I was typing with my elbows. That first paragraph isnt even finished...

    I'd better get to work on this stuff. Suggestions still very welcome. Especially if I've screwed up somewhere. If its bad, I _really_ want to hear about it.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  10. #10
    Okay, the changes are uploaded. Slightly different colours as well. A little easier on the eyes.

    >>Bit worried about your assignment operator in the op overloading section.

    I had a look at what I'd done and I think if you look again you'll see that that particular function is a little different that maybe you expected. It takes an argument of char * so theres no way it can be assigned to itself. The origional unedited class contained an overloaded function for assigning other _SafeStrings but this one doesnt for the sake of clarity. Its _very_ paired down to avoid confusion. I'll leave it as-is.

    Everything else better now?

    Hopefully this will be found useful...
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How's my new Website
    By asbo60 in forum General Discussions
    Replies: 53
    Last Post: 07-10-2009, 10:10 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM