C++ Coding Style
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
No programing questions in the lounge!
Abhishek The worst loneliness is not to be comfortable with yourself. --Mark Twain
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
You'd be better asking this in the C++ forum...
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
EscapeKey wrote:
1.) Why most functions are named in lower case?
Hmm, i think you will only see them in c code.
EscapeKey wrote:
2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()?
PrintFormat()? Whats that? Don't you use printf() to display something?
EscapeKey wrote:
3.) Why do we need something like HWND, HINSTANCE, instead of a simple int?
For easier understanding maybe? If you got a int value from a function, how can you know if it should be used as a handle or other uses without refering to the comments or documenation?
EscapeKey wrote:
4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal?
I self-learn win32 api before MFC but i still do not know how to create a menu without the editor. Certainly it will be good to know how but it isnt necessary really.
Weiye Chen Time may have changed my life, but my heart remains the same to you... Time may have changed my heart, but my love for you never change...
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
EscapeKey wrote:
How could someone possiblily learn and use MFC without learning the win32 api?
Easily, that's like saying "How can you possibly learn and use C++ without learning assembler?". People learn what they need to learn to get the job done.
"He's got a lot on his mind, and it's not a load-bearing structure." - John Weak
-
EscapeKey wrote:
How could someone possiblily learn and use MFC without learning the win32 api?
Easily, that's like saying "How can you possibly learn and use C++ without learning assembler?". People learn what they need to learn to get the job done.
"He's got a lot on his mind, and it's not a load-bearing structure." - John Weak
Steve_Harris wrote:
People learn what they need to learn to get the job done.
Reminds me of a question that has been bothering me. Is it important to just get the job done? In terms of coding, isn't it more important to do it in a more efficient way? :confused: Aw... no need to reply. I am just frustrated right now.. X|
Weiye Chen Time may have changed my life, but my heart remains the same to you... Time may have changed my heart, but my love for you never change...
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
1 - they aren't 2 - because if you want needlessly verbose, VB.NET is waiting for you 3 - Because it differentiates between an int and, well, an int, by making clear what that number represents. If a function takes HWND or if it takes an int, you'd expect to use them very differently 4 - Do you understand exactly how your PC works ? If not, how can you possibly use it ? Seriously, this is a bizarre question from a beginner. By all means, jump in at the deep end if you want to, I'm an advocate of learning MFC first tho, because it is a means of taking byte sized ( har har ) pieces and learning a bit at a time. Only a moron would use Win32 over MFC by default as far as I can see. If you want to take longer to deliver your products for no good reason, just use assembler and be done with it, or at least use C, which is really what Win32 is for. That's why it uses HWNDs instead of just wrapping it's handles in classes.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
No programing questions in the lounge!
Abhishek The worst loneliness is not to be comfortable with yourself. --Mark Twain
This isn't technically a programming question. If he had posted this in the C++ forum, nobody would have answered it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Steve_Harris wrote:
People learn what they need to learn to get the job done.
Reminds me of a question that has been bothering me. Is it important to just get the job done? In terms of coding, isn't it more important to do it in a more efficient way? :confused: Aw... no need to reply. I am just frustrated right now.. X|
Weiye Chen Time may have changed my life, but my heart remains the same to you... Time may have changed my heart, but my love for you never change...
If you're in an extreme time crunch to get if done, you normally don't have time for "efficiency", but you should NEVER sacrifice quality in deference to "the schedule". Most managers will (grudgingly) give you the time to do it right if you make enough noise about it. Of course, the more experience you have, and the more ability you've demonstrated in the past goes a long way towards your credibility when whining about "the schedule".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
1 - they aren't 2 - because if you want needlessly verbose, VB.NET is waiting for you 3 - Because it differentiates between an int and, well, an int, by making clear what that number represents. If a function takes HWND or if it takes an int, you'd expect to use them very differently 4 - Do you understand exactly how your PC works ? If not, how can you possibly use it ? Seriously, this is a bizarre question from a beginner. By all means, jump in at the deep end if you want to, I'm an advocate of learning MFC first tho, because it is a means of taking byte sized ( har har ) pieces and learning a bit at a time. Only a moron would use Win32 over MFC by default as far as I can see. If you want to take longer to deliver your products for no good reason, just use assembler and be done with it, or at least use C, which is really what Win32 is for. That's why it uses HWNDs instead of just wrapping it's handles in classes.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
>> Only a moron would use Win32 over MFC by default as far as I can see. Are you sure? I think using a high level framework is good in general, but it depends on the technology your are using. If you use VB, you expected it to be a high level language and the lack of understanding on the underlying logics are also expected. VB was designed for simple in mind. The VB runtime act as a very thick layer between VB code and the underlying win32 api. I think the VB runtime was designed to wrap the VB world into a sphere. In contrast, I think the MFC is a relatively thin layer between the win32 api. The MFC doesn't wrap and close the win32 api but instead, more like a thin layer of utilities and wrappers for win32 programmer to shorten their coding time. This layer is so thin that you will sooner or later have to use win32 api to solve or work-around a problem. Therefore, I think understanding, or at least, knowing, the win32 api is still essential for working with MFC. I am a beginner and please correct me if I am wrong.:)
-
I am learning C++ and I have several questions regarding the C++ coding style. 1.) Why most functions are named in lower case? 2.) Why the extensive use of shorts such as printf(),instead of PrintFormat()? 3.) Why do we need something like HWND, HINSTANCE, instead of a simple int? 4.) How could someone possiblily learn and use MFC without learning the win32 api? I see someone who considered themselve as experienced C++ programmer, and they can create a working MFC app, but they can't create a menu without a resource editor. I mean, creating menu is probably the first thing I learn in Windows programming. Is that normal? Thanks in advance.:)
- they_are_only_written_like_this_in_K&R_C InC++TheyAreWrittenMoreLikeThis. 2) Dont you hate typing too? 3) Why not give all your variables the same name too, it'll make it so easy to read. 4) C++ has nothing to do with MFC and the WIn32 api. After all, if you cant paint bitmaps on the screen and capture mouse coordinates to make your menus function then you arent much of a C++ coder either. (ever written a mouse, button and menu app in DOS?)
Truth is the subjection of reality to an individuals perception
-
>> Only a moron would use Win32 over MFC by default as far as I can see. Are you sure? I think using a high level framework is good in general, but it depends on the technology your are using. If you use VB, you expected it to be a high level language and the lack of understanding on the underlying logics are also expected. VB was designed for simple in mind. The VB runtime act as a very thick layer between VB code and the underlying win32 api. I think the VB runtime was designed to wrap the VB world into a sphere. In contrast, I think the MFC is a relatively thin layer between the win32 api. The MFC doesn't wrap and close the win32 api but instead, more like a thin layer of utilities and wrappers for win32 programmer to shorten their coding time. This layer is so thin that you will sooner or later have to use win32 api to solve or work-around a problem. Therefore, I think understanding, or at least, knowing, the win32 api is still essential for working with MFC. I am a beginner and please correct me if I am wrong.:)
EscapeKey wrote:
Are you sure?
Yes. It is about 10 times quicker to throw an app together using MFC.
EscapeKey wrote:
or later have to use win32 api to solve or work-around a problem
Very rerely. Some 90% of the win 32 api is wraped by MFC (setwindowshook being one usefull example of what isnt wrapped by MFC)
EscapeKey wrote:
Therefore, I think understanding, or at least, knowing, the win32 api is still essential for working with MFC.
At some stage you will be presented with the 'if you dont know assembler you dont know real coding'. Choose your stopping off point and do it (which usually depends on who pays the bills)
Truth is the subjection of reality to an individuals perception
-
1 - they aren't 2 - because if you want needlessly verbose, VB.NET is waiting for you 3 - Because it differentiates between an int and, well, an int, by making clear what that number represents. If a function takes HWND or if it takes an int, you'd expect to use them very differently 4 - Do you understand exactly how your PC works ? If not, how can you possibly use it ? Seriously, this is a bizarre question from a beginner. By all means, jump in at the deep end if you want to, I'm an advocate of learning MFC first tho, because it is a means of taking byte sized ( har har ) pieces and learning a bit at a time. Only a moron would use Win32 over MFC by default as far as I can see. If you want to take longer to deliver your products for no good reason, just use assembler and be done with it, or at least use C, which is really what Win32 is for. That's why it uses HWNDs instead of just wrapping it's handles in classes.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
There is a reason that race cars use manual transmissions instead of automatics. There are times when it's beneficial to use the low-level stuff.
-------------------------------- "All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
-
>> Only a moron would use Win32 over MFC by default as far as I can see. Are you sure? I think using a high level framework is good in general, but it depends on the technology your are using. If you use VB, you expected it to be a high level language and the lack of understanding on the underlying logics are also expected. VB was designed for simple in mind. The VB runtime act as a very thick layer between VB code and the underlying win32 api. I think the VB runtime was designed to wrap the VB world into a sphere. In contrast, I think the MFC is a relatively thin layer between the win32 api. The MFC doesn't wrap and close the win32 api but instead, more like a thin layer of utilities and wrappers for win32 programmer to shorten their coding time. This layer is so thin that you will sooner or later have to use win32 api to solve or work-around a problem. Therefore, I think understanding, or at least, knowing, the win32 api is still essential for working with MFC. I am a beginner and please correct me if I am wrong.:)
EscapeKey wrote:
Are you sure?
Absolutely. Why walk when you can take a car ? Why write assembler when you can write C++ ? Why use Win32 if you can get the job done in less than half the time with MFC ?
EscapeKey wrote:
but it depends on the technology your are using.
Sure - I said 'without good reason'. MFC should be the default, it's the easiest and best supported C++ approach. But sometimes Win32 is better. I wrote my own windowing framework, which interfaced to Python. I used Win32, why put another framework on top of Win32 when I was writing my own ? There are times when Win32 makes sense, but if you're going to make a general statement, the general truth is than MFC is a better choice.
EscapeKey wrote:
VB was designed for simple in mind
You TOTALLY rock.
EscapeKey wrote:
n contrast, I think the MFC is a relatively thin layer between the win32 api
It is incredibly thin at times. And you get the source code. That's what rocks, once you know MFC, it's easy to step in and see what it's wrapping and how, to learn Win32 after learning MFC ( which many people learn while learning C++ ). Along the way, MFC helps you learn how to do things in an OO way, which Win32 very much can't, as it's a C API.
EscapeKey wrote:
This layer is so thin that you will sooner or later have to use win32 api to solve or work-around a problem.
Absolutely. Again, that's why I advocate the approach I do. Win32 will rear it's head in lots of little ways that you won't even notice until you set out to learn Win32 and realise how often you were already using it.
EscapeKey wrote:
Therefore, I think understanding, or at least, knowing, the win32 api is still essential for working with MFC.
Well, that's not really what you said. If you had said this, I would have agreed, somewhat, in that learning MFC is a small step from learning Win32 at times, and you will learn parts of Win32 while using MFC, by default.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
There is a reason that race cars use manual transmissions instead of automatics. There are times when it's beneficial to use the low-level stuff.
-------------------------------- "All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
Gee - who didn't see this coming ? I said : Only a moron would use Win32 over MFC by default as far as I can see. In other words, yes, sometimes you need a racecar, but some times a push bike does the job just fine at a much lower cost. For most people, an average car is what they need, and for most apps, MFC is the best way to go. That doesn't mean that a race car driver should be compelled to use a Datsun 180B, nor does it mean that MFC is always the best choice. It just is *most* of the time. The OP made a comment to imply that the default should be Win32, and that is not the case. You didn't say it was, but you did seem to miss my point.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Gee - who didn't see this coming ? I said : Only a moron would use Win32 over MFC by default as far as I can see. In other words, yes, sometimes you need a racecar, but some times a push bike does the job just fine at a much lower cost. For most people, an average car is what they need, and for most apps, MFC is the best way to go. That doesn't mean that a race car driver should be compelled to use a Datsun 180B, nor does it mean that MFC is always the best choice. It just is *most* of the time. The OP made a comment to imply that the default should be Win32, and that is not the case. You didn't say it was, but you did seem to miss my point.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Christian Graus wrote:
but you did seem to miss my point.
OK, I agree that I misinterpreted your point. I just wanted to get in a plug for my preference of using the low-level stuff. :-O
-------------------------------- "All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
-
- they_are_only_written_like_this_in_K&R_C InC++TheyAreWrittenMoreLikeThis. 2) Dont you hate typing too? 3) Why not give all your variables the same name too, it'll make it so easy to read. 4) C++ has nothing to do with MFC and the WIn32 api. After all, if you cant paint bitmaps on the screen and capture mouse coordinates to make your menus function then you arent much of a C++ coder either. (ever written a mouse, button and menu app in DOS?)
Truth is the subjection of reality to an individuals perception
fat_boy wrote:
ever written a mouse, button and menu app in DOS?
I have! It was fun too...
-- Torn from tomorrow's headlines
-
- they_are_only_written_like_this_in_K&R_C InC++TheyAreWrittenMoreLikeThis. 2) Dont you hate typing too? 3) Why not give all your variables the same name too, it'll make it so easy to read. 4) C++ has nothing to do with MFC and the WIn32 api. After all, if you cant paint bitmaps on the screen and capture mouse coordinates to make your menus function then you arent much of a C++ coder either. (ever written a mouse, button and menu app in DOS?)
Truth is the subjection of reality to an individuals perception
fat_boy wrote:
(ever written a mouse, button and menu app in DOS?)
Oh yes. And it was fun to write but didn't leave much time for writing the rest of the app.
Michael CP Blog [^] Development Blog [^]
-
- they_are_only_written_like_this_in_K&R_C InC++TheyAreWrittenMoreLikeThis. 2) Dont you hate typing too? 3) Why not give all your variables the same name too, it'll make it so easy to read. 4) C++ has nothing to do with MFC and the WIn32 api. After all, if you cant paint bitmaps on the screen and capture mouse coordinates to make your menus function then you arent much of a C++ coder either. (ever written a mouse, button and menu app in DOS?)
Truth is the subjection of reality to an individuals perception
-
EscapeKey wrote:
Are you sure?
Absolutely. Why walk when you can take a car ? Why write assembler when you can write C++ ? Why use Win32 if you can get the job done in less than half the time with MFC ?
EscapeKey wrote:
but it depends on the technology your are using.
Sure - I said 'without good reason'. MFC should be the default, it's the easiest and best supported C++ approach. But sometimes Win32 is better. I wrote my own windowing framework, which interfaced to Python. I used Win32, why put another framework on top of Win32 when I was writing my own ? There are times when Win32 makes sense, but if you're going to make a general statement, the general truth is than MFC is a better choice.
EscapeKey wrote:
VB was designed for simple in mind
You TOTALLY rock.
EscapeKey wrote:
n contrast, I think the MFC is a relatively thin layer between the win32 api
It is incredibly thin at times. And you get the source code. That's what rocks, once you know MFC, it's easy to step in and see what it's wrapping and how, to learn Win32 after learning MFC ( which many people learn while learning C++ ). Along the way, MFC helps you learn how to do things in an OO way, which Win32 very much can't, as it's a C API.
EscapeKey wrote:
This layer is so thin that you will sooner or later have to use win32 api to solve or work-around a problem.
Absolutely. Again, that's why I advocate the approach I do. Win32 will rear it's head in lots of little ways that you won't even notice until you set out to learn Win32 and realise how often you were already using it.
EscapeKey wrote:
Therefore, I think understanding, or at least, knowing, the win32 api is still essential for working with MFC.
Well, that's not really what you said. If you had said this, I would have agreed, somewhat, in that learning MFC is a small step from learning Win32 at times, and you will learn parts of Win32 while using MFC, by default.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Christian Graus wrote:
EscapeKey wrote: VB was designed for simple in mind You TOTALLY rock.
:laugh:
"He's got a lot on his mind, and it's not a load-bearing structure." - John Weak