How to Make a Nice Block of Commenting in Visual Studio - visual-c++

I just switched back to c++ after leaving it for awhile and I can't seem to remember how to make nice function/class comment boxes in VS. What I'm looking for is something like this:
/**
* Convenience struct: coord
* -------------------------
* Simple C++ struct (which is like a class, except there are
* no methods and everything is public) that bundles two related
* pieces of data together.
*/
struct coord {
int row;
int col;
};
I don't, however, want to have to format out the nice starring and alignment every time I want to write a new comment. I feel like I used to be able to just type '/**' and then hit return and it would automatically make a comment section for me where every time I hit return a new star would appear aligned with the others. Is there a way to activate this in VS 2010?

Visual Assist is the tool you require. If you can move away from MSVC IDE, can try Eclipse also.

You should be able to record a nice macro to do this, then bind it to an unused button/shortcut key combo and your set, else its pretty trivial to code a simple VS plugin to do this with some extra embelishments

Try GhostDoc for a starting point. It is fairly configurable and gives you a documentaion template with one hotkey sequence.
[Edit]
I mistook this for a C# question. As Billy pointed out, GhostDoc is not a good solution for C++ in VS.
Try this SO question about "GhostDoc for C++?" for some other ideas.

Related

Android Studio using Kotlin - is there a way to automatically fold multiline comments?

Been getting into Android Studio (and Android development in general) lately, mostly a personal challenge to make a modern version of an app my mum loves but hasn't been updated in ages. But my life story isn't the point, and that's not just because it's not that interesting.
The actual question:
Is there a way to make Android Studio do automatic folding for block comments (i.e. /* to */) in Kotlin files? In Settings > Editor > Code Folding there's options for documentation (in general) and multiline comments for C or Java, but no settings specific to Kotlin, and just one for Android in general (which has nothing to do with comments).
The reasoning: Because I'm still pretty new at this, there's a lot of things I've tried but haven't worked, and comment out instead of deleting because I still might be able to learn something from them later. There's also some big blocks of logging code for debugging that are great when I'm trying to debug but in the way (given I usually write them in the middle of classes or methods) when I'm not, so I comment them out. It's just annoying having to fold several sections of comments whenever I open a file.
The "well duh" solution?: I could set them as documentation comments, which would hopefully get automatically folded, but if I start writing documentation (like I really should get around to) they'll get mixed in and that would be annoying.
What I've tried so far: Going through all the settings with a fine tooth comb (and I'll freely admit I could have gone over something obvious) and searched for plugins for code folding, about the only one I could find is https://plugins.jetbrains.com/plugin/12007-foldingplus which doesn't seem to do anything about this particular problem.
Can anyone help me out here, other than maybe "be less of a newbie in general"?
With Android Studio Arctic Fox I found that if you highlight a region that has the comments in question, you can right-click on it and one of the options will be Folding. From the expanded options select Fold Selection / Remove Region and the selected comments will fold.

Having trouble creating a class in c++

The problem I'm having seems to be that C++ doesn't like me inserting either or into my class. Part of the problem might be that I'm flipping back and forth between Visual Studio 2010 at my house and Visual Studio 2012 on the school computers (to clarify, this is just something I'm writing for fun, not as a school project). Even when I comment out the parts of the program that deal with the string, c++ still doesn't recognize "cout" or "endl", which is frustrating. Spellcheck seems to be wigging out on me, especially when it comes to #ifndef and #endif. Pastebin contains both the class itself and the error message I get when I try to build it.
Class/errors
Compiler does not recognize string so it throws a tantrum. There's std::string though. If this is just one .cpp file the simplest would be to place using namespace std; after the last include.
More proper solution (that you should use in big projects) is to put std:: everywhere it needs to be put (std::string, std::cout...).

Block auto-format ignore command in visual studio

I love using the Auto Formatting tool in Visual Studio CTRL K + CTRL D However, there are times when VS makes the formatting just a tad off from what I want if, for instance, I'm making a detailed kind of pseudo-code that relies on specific comments and indentation. Is there a way I can still use the CTRL K + CTRL D command and set visual studio to ignore a certain block of code or set of line numbers? Also, if there's an answer in VS 2013 but not in 2012, please post because I may be upgrading soon. Thanks in advance.
I got hit by this problem today with my pseudo-code comments too and thought I'd share the way I solved it.
While there is no way to prevent Visual Studio from auto-formatting parts of code, there is a way to prevent it from auto-formatting pseudo-code comments.
Instead of using something this like this
// if condition
// do this
// else
// do something else
use the tripple-slashes /// instead
/// if condition
/// do this
/// else
/// do something else
As a bonus you get automatic insertion of /// in new lines and auto-indenting that keeps previous row's indentation level.
This seems not to depend on editor indentation options.
It also seems not to mess up XML documentation
(Yes, I know this is an old question. No, I do not want to take Cameron's right for accepted answer.)

Finding all references of a variable or a method in Xcode4

There'a a similar question here but I couldn't make use of the answers in XCode 4. I googled it but I couldn't come up with anything useful either. What's your effective method of getting this information?
Find in project, though if you are searching to change the name everywhere, better would be to use the Refactoring menu.
EDIT: You can use Refactoring to find where a specific variable is referenced. Select the variable and choose Edit->Refactor->Rename. In the refactoring screen, rename the variable (just add _ at the end or something) and click preview. it will show everywhere in the project that variable is referenced. Click on each file to see the lines where the variable is called. After you're done just cancel the refactor.
I highly recommend you try appCode, by JetBrains.
JetBrains have a lot of experience making IDEs (yes, even more than Apple ;) and have done an amazing job with even the EAP of appCode. Find usages, plus a lot more works very nicely.
You can simply open your existing xcode project file in appCode, then Search --> Find Usages.
As Casebash points out here, there actually is a way to search for symbols in Xcode, but unfortunately it's not at all intuitive or convenient to use.
First, open the Search Navigator (Cmd+Shift+F) and change the Style to Symbol References. Then type the name of the symbol into the search box (if it's just a variable name you can select it in the code and type Cmd-E to copy it to the search field). If searching for a method, be sure to use the colon-delimited notation like so:
doSomethingForObject:withParameter:andOtherParameter:
Now if someone could convince Apple to just add a contextual menu item for this, I would be a happy camper. :)
The best way is to do a full text search of the project: CMD-SHIFT-F.
For methods and properties, just use the Related Files menu as I describe here: https://stackoverflow.com/a/17931752/1709587
For variables, there is no easy way to specifically find references, per se (you'll need to use AppCode or the ugly, slow, cumbersome refactor hack), but you shouldn't normally need to. Public member variables are rare in Objective-C, so generally variables are only referred to within the file in which they are declared. A plain text search for the variable name using cmd+f should suffice, usually.
I think instead of doing the refactor hack above. A faster way to find variable references of a particular class is to change the name of the variable (add a letter to the end) in the defining class and hit compile. The compiler will then give you an error for every place that referenced the original variable name.
#property (nonatomic, strong) NSString * url;
becomes
#property (nonatomic, strong) NSString * urlt;
and the compiler happily tells you of every place that uses it:
This is for Xcode 11 for finding the usages of a function, it took forever to find:
Right click the name of the function.
Select "Show Code Actions"
Select "Callers..."
Not sure why Apple made this very basic functionality so complicated

What Resharper features should be highlighted?

On next week I will be talking in front of my colleagues about Resharper as a tool which improves developers' performance. Because time for this talk is limited the question is - what resharper features are worth to be spoken about more then the others?
At the moment I can think of:
code analisys/highlight
unittest runner
refactoring features (rename, extract methods, ...?)
Other than the ones already stated, I would like to add this ones:
Code verification and highlight the code that does not compile on the fly;
Ctrl + Click goes to definition;
Code suggestion/improvements (null reference exception, convert to, etc.);
Find references is way more powerful (with go to definition and go to implementation).
I agree that a demo is probably the best, and configure the infos/errors/warnings beforehand, some of them are overkill/unused.
Demo (live on the beamer) what it can do: analysis, refactoring, unit test... Don't go into details as it pretty much explains itself.
Then focus on important things that they might not discover themselves: How to configure the warnings, code formatting, keyboard shortcuts. (I really love the context sensitive Ctrl-Shift-R / Alt-Enter)
The most important thing: R# lets you write clean, concise and mostly error-free code (at least when it comes to syntactical errors) and greatly lifts up a developer's productivity.
Things that seem most attractive to me:
The many context sensitive Refactoring options (rename, move to another namespace, extract etc...)..
The environment and context sensitive Live templates.
All these options are accessible via shortcuts (which are well worth to learn...)!
If you are doing Test-driven development, you might also find the Unit test integration noteworthy...
Thomas
File Structur window.
Without that defining regions would not be so useful.
Search patterns that can be shown as errors or warnings are also pretty cool.
Navigation (Ctrl + T, F12, Alt + Home, Alt + End,...)
This is one of the coolest features in R# 5.
Go to type (Ctrl+T).
I use it in combination with "Locate in Solution Explorer" (Shift+Alt+L).
(Ctrl + Shift + T) to find/search or open file
This may sound sarcastic, but it's not: The ability to disable resharper, from Tools -> Options -> Resharper ->General -> Suspend. While resharper is awesome, it is sometimes soooooo slow. We have many different solutions, some of which are huge, and it can literally add 5 to 10 minutes to the time it takes to open and/or build our larger solutions. I love that I can suspend resharper when I don't need it and when working on the larger solutions, and then just re-enable it again on the days that I do need it and when I'm working in smaller solutions.
The actual features that I use most are:
Ctrl+Shift+T to find files (works better than the VS native Ctrl+,).
Alt+Enter for code improvements.
The code suggestions given with blue/red squiggles.
The little glyph it puts beside unit tests, so you can easily run a single test.
Go To Implementation is great when working with projects using IoC.

Resources