Finding inheritors of a class across branches of code - c#

Has anyone attempted something similar to "find inheritors" or "find references" across branches? I'm working with a code base that includes multiple release branches, some of which differ from the main line.
Fortunately, the base code is no different, but there may be classes that inherit that base code. When making redesign decisions, it would be helpful to know which branches might be affected by a redesign. Has anyone run into this in the past and/or knows a good direction in which to point me to find more information on the topic?
I'm working with C#, Visual Studio, and an SVN repository, but if someone has run into this in other code repositories, other languages, or other technologies, the same concepts should apply.
Thanks in advance for the help!

Your query is similar to find difference between branches in TFS. With TFS, we can find difference in VS directly, by right click on the file or folder in Source Control Explorer and choose Compare. Or we can use command line tool tf.exe to get the difference:
tf diff[erence] itemspec [/version:versionspec] [/type:filetype]
[/format:format [/ignorespace] [/ignoreeol] [/ignorecase] [/recursive]
[/options][/noprompt][/login:username,[password]]
You may check whether SVN has similar command line tool.

Related

How to use an altered Roslyn in Visual Studio

C# isn't enough for me, so I've taken advantage of the newly-open sourced Roslyn to extend it, say by modifying it to use French quotes.
But I don't want to build my newly-French-quoted files on the command line! I want Intellisense! I want a nice UI! In short, I want to get Visual Studio to use my Roslyn, not Microsoft's.
Can I do this yet? If so, how?
Quoted straight from this link in your question:
ADVANCED USAGE
It is also possible to update your copy of Visual Studio to use your
own built version of Roslyn (for example, to see how the IDE reacts to
your changes), but it’s slightly complicated:
First of all, you’ll need to use the release fork, not the master
fork. This is because the compiler code is constantly changing in
reaction to feedback, and that includes changes to the APIs that are
used by the non-open IDE bits in the Roslyn preview in order to access
compiler information (until the APIs get locked down as we get closer
to completion). When these APIs change, the ability to communicate
between the two is lost. The release fork, however, accurately
reflects the state of the code at the time that the Roslyn preview was
snapped, and so is safe to use as a baseline for this sort of thing.
(You can see the fork on the Roslyn CodePlex site by choosing “Source
Code” and then opening the “Browsing changes in” dropdown – it’s
called “releases\build-preview.”)
To switch to this fork in Git, you will need to execute the following
two commands from an appropriate Git prompt in your enlistment:
Git fetch
Git checkout – track origin/releases/build-preview
Your git repository will now have the contents of the
releases/build-preview branch. Once you’ve done this, you can switch
back and forth between the branches using Git checkout master and git
checkout releases/build-preview. (Details on Git usage are beyond the
scope of this blog; see
http://www.git-scm.com/book/en/Git-Branching-Remote-Branches for more
information on branching in Git.)
Second, you’ll need to disable Visual Studio’s strong-name assembly
checking for the relevant assemblies first. There’s a script to help
with that, which you can find checked into the source code at
Src/Tools/Microsoft.CodeAnalysis.Toolset.Open/Scripts/Prepare.bat.
With all of that done, make your changes. Then, after building, ensure
that CompilerPackage is set as the startup project, and then
F5/Ctrl+F5 to launch a VS instance containing the changes.
Please note that we will never accept pull requests for the release
fork – we need to keep it pristine and accurately reflecting the state
of the code relative to the Roslyn preview bits. Anything you actually
want considered for submission would need to be ported to a fork
created from the master first.
Interesting times ahead. Though I have a certain amount of trepidation about finding myself in a company where they use an entirely customised compiler to do awful, awful things. The gun to shoot yourself in the foot with has just been upgraded...

Compare (and merge) two VS C# projects

I have two VS C# projects (specifically, for an Outlook plugin) that I believe to be very similar with the exception of perhaps 100 lines of code. I'm slightly worried that there might be other configuration options for the project that are different, so I'd like to compare those two.
What is the best way to see the differences between the two codebases?
I've tried putting the two projects in parallel directories and using diff, but since the projects are named differently, some of the files don't match up. I'm just wondering if there's an easier way to do this?
It sounds like you need something like WinMerge to go through and point out the differences between the two projects. It's free, and I know you can compare folder contents with WinMerge, so that's probably a good place to start. Run WinMerge on the project folders and it should generate a detailed comparison outlining the differences between the files.
See this tutorial on comparing folders:
http://manual.winmerge.org/CompareDirs.html
I strongly recommend Code Compare (not affiliated, just a happy user) for this kind of job - there is a free version and a more advanced commercial version.
It integrates nicely with VS and has syntax highlighting for C#, C/C++ etc.
One way: Make copies of both projects, rename the files and folders in one to match the files and folders in the other, then use your favorite folder compare tool to compare the two.
This won't help you unless there was a true copy-and-paste relationship between the two projects.
The better way would be to use refactoring. After creating unit tests for both projects and achieving an adequate level of code coverage, go class by class and method by method using refactoring to try to make pairs of methods identical. You may then identify methods that should be pulled into base classes or moved into other classes.
Eventually, you may find pairs of classes which are identical. Move those classes into a common library, then rename all uses of one of the classes to be a use of the other. Then delete the one no longer used.
Repeat until there is no more duplication.
If you've got modifications like renames or partial code moves, importing both versions into a single git repository (as two different commits of a single directory) could help. Git tracks contents of files, not the files themselves, so it is possible to find out e.g. a function that has been moved from one file to another.

Common Lisp IDE for C# Developer?

UPDATE
I've decided to go with Clojure for now.
LispDev isn't ready, and Eclipse/cusp wasn't stable enough for me to feel comfortable.
As for Clojure, after a long, very frustrating, very annoying process trying to get Eclipse/CCW, Netbeans/Enclojure and IntelliJ/La Clojure working, I finally got Eclipse/CCW working. The rest are still in mostly-broken states.
(If I get around to it, I'll document what it took for me to get Eclipse/CCW working.)
So for now, I'm going to use that. I may dip back into CL, and check out LispWorks and AllegroLisp's free versions, but Clojure feels like a more natural step for me from working within the Microsoft CLR environment.
Thanks everyone for the help.
Original Question
I'm a C# developer very familiar with Visual Studio (with Resharper).
I'm new to Lisps. I've taken an interest in both Common Lisp and Clojure recently, and found plenty of good material on both of them.
I've tried Emacs + Slime, but it feels like a very backwards, dated solution. I have no doubts about its power, but it's usability is nothing like what I'm used to. I don't want to struggle with an IDE in addition to the language.
There are Eclipse plugins for both Clojure and CL. There's also a couple more options I've seen for Clojure. Since I'm not a Java dev, I know nothing about these IDEs.
Is Eclipse a good place to start? Are there other good options?
EDIT:
Here's the features I'm used to:
Syntax highlighting and autoindentation (everyone has this, so it's a moot point)
Autocomplete of functions and variable names
Realtime displays of all function overloads and parameters and the ability to arrow up/down through the list while typing in parameters
Syntax suggestions for code improvement, with the ability to do them for you ("use a const", "convert to LINQ expression (FP)", "variable will never be assigned to", "variable will never be used", "variable could be null", "function will never be used", etc.)
Extract Method/Function refactoring: select a block of text, and it can be extracted into a new function
Create Variable Refactoring: select a block of text and create a variable (e.g., a let)
Rename Refactoring: rename a function or variable declaration and all other functions using it will be updated (automated search/replace)
Go to Definition of a method/function, variable
Find Usages/References to a particular method/function, variable
Integrated folder-based project management tools and build tools
"Move class to new file" which creates a new file based on the class name, and containing all of its methods
"Rename file based on class type" which renames the file if you change the class name
F9/Click to the left of the line to add/remove breakpoints
F10/F11 to step into or over code when debugging, along with an arrow and highlighting to show which code is currently executing (step into a func execution, or just execute it here)
Most everything is available in a right-click context menu, or as a hovering combobox or textbox as you're typing.
I'm not saying emacs/slime can't do that, but if it does, it doesn't use anything similar in terms of usability techniques.
If you're used to Visual Studio and want a similar product for Lisp, the equivalent is probably going to be a similar commercial IDE. The big ones I know of are Allegro and Lispworks.
I've not personally used either one for real work (i.e., a big project), though I've tried demos. They seemed nice enough, if a bit complex and with weird UIs, but not so much better than Slime to be worth the money to me. But if you want something like VS, they may be just what you're looking for.
FWIW, I do both C# and Common Lisp in Emacs, and I find Slime to be 10 times better than any set of modes I've found for editing C# so far. Come to think of it, I don't know of any development environment for any language or platform I'd rather use -- it's that good.
One issue you may have is that Lisp itself is a different enough language than what you're used to that old ways of doing things no longer apply, so any IDE may seem "backwards" to you. (I learned Lisp long before C#, and C# seems backwards and dated to me!) So instead of learning a few Slime commands (there's not many you really need), you're learning IDE commands, which might not really be any easier for you, since the concepts are the same and don't necessarily map to VS-like IDE features.
But good luck with whatever you choose!
C# is mostly used in a batch mode. The IDE shows this. It knows the syntax of a fixed language, invokes a compiler and uses the output from various tools, like the compiler.
Common Lisp is slightly different. The IDEs are either integrated into Common Lisp (Allegro CL, LispWorks, CCL) or are in something like Emacs and connect to a running Lisp (SLIME / Emacs). The major mode of development is interactive. A program is running and the IDE modifies it.
For Emacs one uses SLIME with the extensions Paredit and Redshank. See: Editing Lisp Code with Emacs.
Syntax highlighting and autoindentation (everyone has this, so it's a moot point)
This is provided by the IDEs.
Autocomplete of functions and variable names
This is provided by the IDEs.
Realtime displays of all function overloads and parameters and the ability to arrow up/down through the list while typing in parameters
Common Lisp does not have 'overloads'. It is possible to browse generic functions (CLOS) in IDEs.
Syntax suggestions for code improvement, with the ability to do them for you ("use a const", "convert to LINQ expression (FP)", "variable will never be assigned to", "variable will never be used", "variable could be null", "function will never be used", etc.)
Lisp compilers output hints and warnings. There are also style suggestions by some.
CL-USER 15 > (defun foo (a b) a)
FOO
CL-USER 16 > (compile 'foo)
;;;* Warning in FOO: B is bound but not referenced
FOO
Implementations like LispWorks can browse the set of warnings and errors.
Extract Method/Function refactoring: select a block of text, and it can be extracted into a new function.
Tools may do that. See for example Redshank.
Create Variable Refactoring: select a block of text and create a variable (e.g., a let)
Reshank.
Rename Refactoring: rename a function or variable declaration and all other functions using it will be updated (automated search/replace)
Use the search and replace tools of the IDE. Note that since Lisp has a programmable syntax the problem is not solvable in a general way.
Go to Definition of a method/function, variable
Meta-. , Meta-X Edit definition
Find Usages/References to a particular method/function, variable
Who calls feature in IDEs.
Integrated folder-based project management tools and build tools
See System Tools.
"Move class to new file" which creates a new file based on the class name, and containing all of its methods
Common Lisp does not work this way. Methods and Classes are not connected like in C#.
"Rename file based on class type" which renames the file if you change the class name
Common Lisp does not work this way. One does not write a file for a class.
F9/Click to the left of the line to add/remove breakpoints
Depends on the IDE. Use the function BREAK otherwise.
F10/F11 to step into or over code when debugging, along with an arrow and highlighting to show which code is currently executing (step into a func execution, or just execute it here)
Use the function STEP or the IDE tool.
Most everything is available in a right-click context menu, or as a hovering combobox or textbox as you're typing.
Yes.
I would think you need to check out SLIME in more detail, since it does a lot what you describe in combination with usual Common Lisp features like STEP, BREAK and TRACE.
It might also be useful to read the manual of the LispWorks IDE, which provides the equivalent features in a portable GUI and more:
Lispworks for Windows, IDE User Guide
I'm not saying emacs/slime can't do that, but if it does, it doesn't use anything similar in terms of usability techniques.
SLIME is based on Emacs, so it is shaped by its UI. LispWorks for example uses the Emacs ideas mostly only for the editor component (which is based on an Emacs-like editor written in Common Lisp). LispWorks uses GUI tools for class browsing, generic function browsing, system management, the debugger, inspector, etc.
Maybe you should give Jabberwocky a try.
There's also LispIDE, and Lisp Studio.
Allegro Common Lisp has an IDE supplied with it which may be of interest (although I'm not sure if you can use it with other Lisps). The Eclipse plugin is called Cusp and can be found here, although there's a fork of it here called lispdev which may have been updated more recently.
There may be some useful stuff over at the Lisp Game Wiki, especially the Useful Applications page here.
Personally I like using Emacs+Slime with some of the emacs tools which are designed to make it more IDE like.
While this question is old, and the OP has turned to Clojure, I think this is still a valid question, especially for those looking to learn Common Lisp and are either reluctant to switch from Visual Studio or just want to learn something new with a tool they are familiar with, to at least reduce the barrier to entry into such a great language, the same reasons why this question was asked.
I wrote an article explaining exactly how to achieve this, using Visual Studio as a Lisp IDE, which would be an almost great substitution for EMACS + SLIME combination.
The steps to achieve this setup are:
Visual Studio 2015 (Obviously the main ingredient)
Lisp Integration Visual Studio Extension.
Have ConEmu already installed and grab the ConEmuIntegration Visual Studio Extension.
A Common Lisp implementation of your choice, set in your %PATH% (via Environment Settings)
With that setup above, you will have an embedded REPL, and hovering the mouse over the Lisp functions/macros will give you tooltips with the signatures and definitions. This should accomplish most of the features requested in the original question.
It may have been unfortunate that at the time this question was asked, these tools weren't mature enough/created to be fully integrated as it is now, OR no one was aware or interested enough at the time.
As a bonus, if you are already familiar with C++, my recommendation would be to check out Embeddable Common Lisp (ECL), as that allows you to embed Lisp into your C++ code or call C++ from Lisp, how great is that combined with Visual Studio?
If you are new to Lisp and not an emacs user presently, then I would strongly recommend the free editions of either Allegro Lisp or LispWorks. Or, if you are going the Scheme route, PLT Scheme (which is now called Racket).
All three have very feature rich IDE's. Calling trees, type ahead, in-editor breakpoints, and most of the things you are used to from traditional IDE's.
I know this is an old question but - for Clojure - how about Nightcode? I similarly didn't want to waste language-learning time learning a new editor (i.e. Emacs/SLIME) too. I found Nightcode very usable.
https://nightcode.info/
I find myself now wanting Nightcode to support Common Lisp (maybe in the form of ABCL) too!

Adding Generic Test Cases to TFS in C#

So I'm trying to find a way in which I can insert new generic test cases into TFS through C#. These are the same ones that you can create in Visual Studio so I was hoping there was someway to do this with the TFS API somehow. Any hints of suggestions are greatly appreciated.
Thanks!!
The key difference Ewald is pointing to is that there are Test Case Work Items (logical sets of tests you need to execute as a piece of recorded work) and physical tests that can verify behavior. Generic Test is a artifact that executes another tool and verifies the rseults of that other tool. It really has little direct relationship to TFS. These are things you add to a Visual Studio Test Project and can, but are not required to, place in source control (TFS or otherwise).
You can likely you can use an existing Generic Test file as your template for automating this process if you have the need.
Follow these instructions http://www.ewaldhofman.nl/post/2009/12/11/TFS-SDK-2010-e28093-Part-5-e28093-Create-a-new-Test-Case-work-item.aspx to create a new test case work item to TFS.

How to make a "Call stack diagram"

Creating a call stack diagram
We have just recently been thrown into a big project that requires us to get into the code (duh).
We are using different methods to get acquainted with it, breakpoints etc. However we found that one method is to make a call tree of the application, what is the easiest /fastest way to do this?
By code? Plugins? Manually?
The project is a C# Windows application.
With the static analyzer NDepend, you can obtain a static method call graph, like the one below. Disclaimer: I am one of the developers of the tool
For that you just need to export to the graph the result of a CQLinq code query:
Such a code query, can be generated actually for any method, thanks to the right-click menu illustrated below.
Whenever I start a new job (which is frequently as I am a contractor) I spend two to three days reading through every single source file in the repository, and keep notes against each class in a simple text file. It is quite laborious but it means that you get a really good idea how the project fits together and you have a trusty map when you need to find the class that does somethnig.
Altought I love UML/diagramming when starting a project I, personally, do not find them at all useful when examining existing code.
Not a direct answer to your question, but NDepend is a good tool to get a 100ft view of a codebase, and it enables you to drill down into the relationships between classes (and many other features)
Edit: I believe the Microsoft's CLR Profiler is capable of displaying a call tree for a running application. If that is not sufficient I have left the link I posted below in case you would like to start on a custom solution.
Here is a CodeProject article that might point you in the right direction:
The download offered here is a Visual
Studio 2008 C# project for a simple
utility to list user function call
trees in C# code.
This call tree lister seems to work OK
for my style of coding, but will
likely be unreliable for some other
styles of coding. It is offered here
with two thoughts: first, some
programmers may find it useful as is;
second, I would be appreciative if
someone who is up-to-speed on C#
parsing would upgrade it by
incorporating an accurate C# parser
and turn out an improved utility that
is reliable regardless of coding style
The source code is available for download - perhaps you can use this as a starting point for a custom solution.
You mean something like this: http://erik.doernenburg.com/2008/09/call-graph-visualisation-with-aspectj-and-dot/
Not to be a stuck record, but if I get it running and pause it a few times, and each time capture the call stack, that gives me a real good picture of the call structure that accounts for the most time. It doesn't give me the call structure for things that happen real fast, however.

Categories