Visual Studio question

Homework giving you a headache? Math gives you a migraine? Can't quite figure out how to do something in photoshop? Never fear, the other members of CAA share their expertise in this forum.

Visual Studio question

Postby SnoringFrog » Thu Feb 17, 2011 4:27 pm

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?
UC Pseudonym wrote:For a while I wasn't sure how to answer this, and then I thought "What would Batman do?" Excuse me while I find a warehouse with a skylight...
[SIZE="7"][color="MediumTurquoise"]Cobalt Figure 8[/color][/SIZE]
DeviantArt || Myspace || Facebook || Greasemonkey Scripts || Stylish Userstyles
User avatar
SnoringFrog
 
Posts: 1159
Joined: Tue Jul 26, 2005 9:25 pm
Location: Liberty University, VA

Postby Furen » Thu Feb 17, 2011 6:58 pm

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)
And this I pray, that your love would abound still, more and more with real knowledge and all discernment. Be prepared to preach the gospel at a moment's notice. Do you know the gospel well enough to do so yourself? Be ready.
User avatar
Furen
 
Posts: 2695
Joined: Mon Jul 26, 2010 9:39 pm
Location: Mostly at my PC, but meh, I can be wherever.

Postby shooraijin » Thu Feb 17, 2011 10:06 pm

That's not really a template, though. That's just using the preprocessor.
"you're a doctor.... and 27 years.... so...doctor + 27 years = HATORI SOHMA" - RoyalWing, when I was 27
"Al hail the forum editting Shooby! His vibes are law!" - Osaka-chan

I could still be champ, but I'd feel bad taking it away from one of the younger guys. - George Foreman
User avatar
shooraijin
 
Posts: 9928
Joined: Thu Jun 26, 2003 12:00 pm
Location: Southern California

Postby SnoringFrog » Fri Feb 18, 2011 8:49 am

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.
UC Pseudonym wrote:For a while I wasn't sure how to answer this, and then I thought "What would Batman do?" Excuse me while I find a warehouse with a skylight...
[SIZE="7"][color="MediumTurquoise"]Cobalt Figure 8[/color][/SIZE]
DeviantArt || Myspace || Facebook || Greasemonkey Scripts || Stylish Userstyles
User avatar
SnoringFrog
 
Posts: 1159
Joined: Tue Jul 26, 2005 9:25 pm
Location: Liberty University, VA

Postby Warrior4Christ » Fri Feb 18, 2011 1:51 pm

You could make the template file attribute read-only?
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Furen » Fri Feb 18, 2011 9:39 pm

[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... :/
And this I pray, that your love would abound still, more and more with real knowledge and all discernment. Be prepared to preach the gospel at a moment's notice. Do you know the gospel well enough to do so yourself? Be ready.
User avatar
Furen
 
Posts: 2695
Joined: Mon Jul 26, 2010 9:39 pm
Location: Mostly at my PC, but meh, I can be wherever.

Postby Warrior4Christ » Fri Feb 18, 2011 9:46 pm

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.
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Furen » Sat Feb 19, 2011 10:33 pm

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.
And this I pray, that your love would abound still, more and more with real knowledge and all discernment. Be prepared to preach the gospel at a moment's notice. Do you know the gospel well enough to do so yourself? Be ready.
User avatar
Furen
 
Posts: 2695
Joined: Mon Jul 26, 2010 9:39 pm
Location: Mostly at my PC, but meh, I can be wherever.

Postby blkmage » Sun Feb 20, 2011 10:47 am

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.
User avatar
blkmage
 
Posts: 4529
Joined: Mon May 03, 2004 5:40 pm

Postby Furen » Sun Feb 20, 2011 9:11 pm

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.
And this I pray, that your love would abound still, more and more with real knowledge and all discernment. Be prepared to preach the gospel at a moment's notice. Do you know the gospel well enough to do so yourself? Be ready.
User avatar
Furen
 
Posts: 2695
Joined: Mon Jul 26, 2010 9:39 pm
Location: Mostly at my PC, but meh, I can be wherever.

Postby Warrior4Christ » Mon Feb 21, 2011 12:50 am

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]
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby blkmage » Mon Feb 21, 2011 8:41 am

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.
User avatar
blkmage
 
Posts: 4529
Joined: Mon May 03, 2004 5:40 pm

Postby Furen » Wed Feb 23, 2011 6:47 pm

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.
And this I pray, that your love would abound still, more and more with real knowledge and all discernment. Be prepared to preach the gospel at a moment's notice. Do you know the gospel well enough to do so yourself? Be ready.
User avatar
Furen
 
Posts: 2695
Joined: Mon Jul 26, 2010 9:39 pm
Location: Mostly at my PC, but meh, I can be wherever.

Postby blkmage » Wed Feb 23, 2011 7:17 pm

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.
User avatar
blkmage
 
Posts: 4529
Joined: Mon May 03, 2004 5:40 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 235 guests