Page 1 of 1

Visual Studio question

PostPosted: Thu Feb 17, 2011 4:27 pm
by SnoringFrog
I'm using Visual Studio 2010 Express and I'd like to create a default template for my .cpp files. My computer professor requires a particular header/footer in comments in each .cpp file, and I was wondering if there's a way to set VS up to automatically fill in that stuff for me?

PostPosted: Thu Feb 17, 2011 6:58 pm
by Furen
OH OH OH OH OH OH OH I KNOW (well i'm in 2008 for school, but the headers shouldn't be too different if they are)

go to new file, make a file that ends in .h and in the WhateverYouCalledIt.h type in

#pragma once
#import namespace std
#import "stdfax"
#import "windows.h"

stuff like that, I can't garentee that I spelled those correct, but after you add them all into a header go to the program you want to code and at the top do

#import "WhateverYouCalledIt.h"

and it should all work
(if you need more help, I'll show an example, but I'm using 2008 so it may not work for that reason also)

PostPosted: Thu Feb 17, 2011 10:06 pm
by shooraijin
That's not really a template, though. That's just using the preprocessor.

PostPosted: Fri Feb 18, 2011 8:49 am
by SnoringFrog
shooraijin (post: 1459690) wrote:That's not really a template, though. That's just using the preprocessor.
Yeah, what I really need to include is basic crap like my name/course/assignment#/etc in a comment at the top of the source code. We have to print our .cpp and turn it in, so I need the info in the same file for printing.

I'm just trying to avoid having to type in all the extra stuff that will always be in the comments before/after the actual code. At the moment I have a file I named TEMPLATE that I open and just save as a whatever name I need once I edit it, but I know I'm probably gonna end up hitting ctrl+s and wiping out the template pretty soon.

PostPosted: Fri Feb 18, 2011 1:51 pm
by Warrior4Christ
You could make the template file attribute read-only?

PostPosted: Fri Feb 18, 2011 9:39 pm
by Furen
[color="Lime"]// Commenting is easy, though I agree it's annoying when
//The teacher makes you do it for everything
//As well as for the naming of variables.[/color]

so I don't know the exact problem though... :/

PostPosted: Fri Feb 18, 2011 9:46 pm
by Warrior4Christ
Furen (post: 1459869) wrote:[color="Lime"]// Commenting is easy, though I agree it's annoying when
//The teacher makes you do it for everything
//As well as for the naming of variables.[/color]

so I don't know the exact problem though... :/

No, the best comment is no comment.

PostPosted: Sat Feb 19, 2011 10:33 pm
by Furen
I use comments, though I don't like doing it for EVERY variable numbering sequence, example:

int intH = 100 [color="Lime"]//Health Variable[/color]
but for something like
int intH = 100 [color="Lime"]//health[/color]
cout >> "Please choose a lower number if you want more of a challenge"
[color="lime"]//Telling the user to choose a number less than 100[/color]
cin << intH [color="lime"]//User inputs health[/color]

I understand the first line, and maybe the third, but the middle one is useless, it's in English already, but my teacher makes us do "Proper Coding" which is basiclly a comment after everything minus mathematical statements. but I don't like it when there's no comments either, I read through my classmates codes and have to think a bunch to help them, as where the comments will help me find the problem and how to fix it.

But when I said I don't understand the question, I was talking about the initial question as I wasn't sure if I answered the initial question.

PostPosted: Sun Feb 20, 2011 10:47 am
by blkmage
Jeff Atwood is writing to people who know how to code, and presumably do so well. The reason teachers make students comment excessively in classwork is because people who are learning how to program are obviously very bad at writing good code. You should be writing code in such a way that it is obvious to the reader what is going on without having to resort to comments.

PostPosted: Sun Feb 20, 2011 9:11 pm
by Furen
I agree with that, but many people in my class code well (many don't but a bunch do) I do understand commenting for explaining variables, but when teachers make you do something like:

Sleep (10000) [color="lime"]//Makes code pause for 10 seconds[/color]
cout << "Hi" [color="lime"]// Displays the word Hi to the screen using the C out function[/color]
Sleep (2000) [color="Lime"]//Makes code pause for 2 seconds[/color]


That's the overboard that I know, my teacher knows I can code as I've been in many coding classes with him, but some of the other students either have paragraphs or nothing, and I can see why he gets annoyed.

PostPosted: Mon Feb 21, 2011 12:50 am
by Warrior4Christ
blkmage (post: 1460102) wrote:The reason teachers make students comment excessively in classwork is because people who are learning how to program are obviously very bad at writing good code.

While that is true, and it might be useful / show that a student knows what functions do (although, in using the function and seeing that it works, they've probably demonstrated that they know what it does...), I think many teachers enforce too many comments. For example:
Furen (post: 1460028) wrote:int intH = 100 [color="Lime"]//Health Variable[/color]

Commenting on declaring a variable is unnecessary.. why don't you just name the variable healthValue or something. If you need to explain something about the variable, something like this might be valid:
int healthValue = 100 [color="Lime"]// Must be in range 0-100[/color]

PostPosted: Mon Feb 21, 2011 8:41 am
by blkmage
But I think you illustrated my point exactly. People who are learning are going to be giving things inexplicable names like intH and unless you force them to comment everything, they're just going to be doing stuff like that. It at least lets someone indicate their intentions even if they write something that's otherwise indecipherable. I suspect that the over-commenting rule is not there for the average student, but is for the worst-case student and is not only for the student, but for the marker as well.

I think in large enough classes or interfaces, it's worth commenting on your variables and parameters.

PostPosted: Wed Feb 23, 2011 6:47 pm
by Furen
That one where I declare "IntH" would be what I HAVE to do because of the "Documentation" for everything to be int___ because my teacher makes us do it that way, and I don't want to type out intHealth every time, Health would be fine and even HHealth (hero health) but the intH would just be my lazy coding ways, I still code fine.

PostPosted: Wed Feb 23, 2011 7:17 pm
by blkmage
Again, this is my point. Naming a variable intH is one of the most basic things on the list of bad code red flags. intH is bad code, regardless of context. That you're forced to use Hungarian notation is not your fault (which is silly goosery because of type declarations), but that doesn't mean you can suddenly drop good coding style like naming variables properly.