Common Lisp IDE for C# Developer? - c#

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!

Related

Is there something better than preprocessor directives (#if, etc) in C#?

Most questions of this type are seeking to alter the program behavior (things that could be decided at run time) or want to deal directly with debug printing. This is a bit different.
I have code that depends on a peripheral (like a card reader). Sometimes I don't use it, which means the library isn't present. (And I'm being nice, because "library" turns out to mean installing a 2GB software suite). When I remove the library, I can't open the device. If I can't open the device, I can't create the class member that uses it. With the class inoperative, I can't call its methods from within the code. Therefore, I can't just choose not to execute it; I need it to go away since it will not compile without the library.
Preprocessor directives like #if and all that are ok, maybe; but these things appear in more than one file, which means independently maintaining a #define at the top of each. I come from a simpler place (meaning, C) where one header file can be used to control this. I note that C# is rather hostile about #define (either the label exists, or not; no constants or calculations allowed), and that makes me think there's another way.
How do you handle this?
---Follow-up(s)---
I did read the "duplicate" Q/A's, and have a fairly good picture of what I'm dealing with. I didn't find those questions in my original search, but sometimes that's just how it is.
#Amy suggests that #define at the top is "not how it's done" but rather "put it on the command line". So, (if I realize we are sticking with this mechanism) the discussion might go to examining ways to have that happen . One does not simply drop to a terminal and do that. It happens as "IDE features" or "IDE hacks".
#Alexei Levenkov asks what I really want. I really want to (a) not get compile errors, and (b) do it by selectively leaving out the code. And, find the C# equivalent to the way I proposed.
Some more constraints are addressed by the fact that I haven't been using VS or C# for all that long. So I know a lot less than you all do. Considering I got the code from the last person and have to deal with what I see, I don't want to set up the person after me to have to figure out what "interesting" thing I might have done to make it work. Thus, things like hand-editing a project file may work but will also cause consternation down the line.
# Eric Lippert suggests "hostile" is really "sensible". I may have had my tongue too far into my cheek on that one. VS seems to be telling me I'm doing it wrong, so I sensed there's a "right way" I simply don't know about. As for the 2GB supporting application, I will go to various computers and pull down the repository and try out something, and so this "overhead" wants to propagate with it. It's worse if I'm linked through my phone to do the download. And if I build the application with everything included, the end user is then required to install that software suite before the program will run. In theory, they could be required to buy the software. If I sent you a tic-tac-toe game, and told you it wouldn't run until you installed Oracle, you'd probably pass on the whole thing.
I considered the "stub out the interface" idea, but there seemed to be more hooks into the class than I wanted to deal with. Plus, I don't know what these things do, so I have to know something about them in order to "fake" them.
In the end I decided that we're still largely using the #if scheme to get this done, and the replacement feature I imagined might exist, doesn't. And I'm using the provision in the project file(s) as cited by #Jim G. as it gets the job done and is only a little imperfect. It's good enough.
As #BJ Safdie said here:
Set them in your Compilation Properties or Build options.
You get to the build options by right-clicking the project and selecting
properties from the menu.

How to make make syntax highlighting and keyboard behavior identical for VB.NET and C# in Visual Studio 2008?

C#
Types have their own color (cyan by default).
Enter completes the auto-complete suggestion.
Visual Basic
Types use Identifier color (black by default).
Enter completes the auto-complete suggestion and adds a "()" and a newline.
These and other seemingly minor differences are so enraging I can't get any work done. How do I make Visual Studio behave consistently? Failing that, any other solutions/suggestions?
Edit: I don't care which way, I just want it to be consistent.
The VB.NET and C# IDEs merely look the same. They are actually very different chunks of code that don't have much in common beyond the text editor engine. They did a pretty good job making them look similar, it certainly wasn't that way in earlier releases of VS. But there are subtle differences here and there, like the ones you are fretting over.
You'll need to get over this. Pick, say, global warming or the economy to direct your rage. Or a hapless contributor to SO :)

C# Interpreter (without compilation) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a ready-to-use C# interpreter out there, that is does not rely on runtime compilation?
My requirements are :
A scripting engine
Must Handle C# syntax
Must work on medium-trust environments
Must not use runtime compilation (CodeDomProvider ...)
Open source (or at least free of charge both for personal and professional use)
If this is not clear, I need something like Jint (http://jint.codeplex.com/), but which allows me to write C# scripts instead of JavaScript ones.
Thanks for your help.
Have you looked at paxScript.NET?
Check out the Mono project. They recently demoed CsharpRepl which sounds like what you're after. The PDC 2008 video here.
Update:
On a close look it seems like using Mono.CSharp service to evaluate scripts won't be possible. Currently it is linked to the Mono runtime and they don't expect it to run in a medium trust environment. See this discussion for more info.
On alternative possibility is to include the Mono C# compiler (sources here) in your project and use it to generate assemblies that you load from the file system. It you are worried about the resources required to load all those assemblies you might have to load them in a separate AppDomain.
I need to evaluate 10000+ small
scripts that are all differents,
compiling all of them would be just
dramatically slow
Interpretting these would be even more painfully slow. We have a similar issue that we address as follows:
We use the Gold Parser project to parse source code and convert it to an XML based 'generic language'. We run this through a transform that generates VB.Net source code (simply because it's case insensitive). We then compile these using the .Net runtime into a standalone DLL, and call this using heavily restricted access.
It sounds as though you are creating something like a dynamic website where people can create custom modules or snippets of functionality, but using C# to do this introduces a couple of main problems; C# has to be compiled, and the only way around this is to interpet it at runtime, and this is unfeasible, and even if you do compile each snippet then you end up with 10,000 DLLs, which is impractical and unusable.
If your snippets are rarely changing, then I would consider programatically wrapping them into a single set of source, with each having a unique name, then compile them in a single shot (or as a timed process every 10mins?). This is what we do, as it also allows 'versioning' of peoples sessions so they continue using the version of DLL they had at the start of their session, but when every session stops using an old version then it's removed.
If your snippets change regularly throughout the day then I would suggest you look at an interpretted scripting language instead, even PHP, and mix your languages depending on the functionality you require. Products such as CScript and LinqPad all use the CodeDomProvider, because you have to have IMSL somewhere if you want to program compiled logic.
The only other option is to write your own interpretter and use reflection to access all the other libraries you need to access, but this is extremely complex and horrible.
As your requirements are effectively unachievable, I would suggest you take a step back and figure out a way of removing one or more restrictions. Whether you find a FullTrust environment to compile your snippets in, remove the need for full code support (i.e. move to interpretted code snippet support), or even change the whole framework to something non .Net.
LINQPad can work as a code snippet IDE. The application is very small and lightweight. It is free (as in beer) but not open-source. Autocompletion costs extra but not much ($19).
Edit: after reading over the comments in this post a little more carefully, I don't think LINQPad is what you want. You need something that can programmatically evaluate thousands of little scripts dynamically, right? I did this at work using Iron Ruby very easily. If you're willing to use a DLR language, this would probably be more feasible. I also did some similar work with some code that could evaluate a C# lambda expression passed in as a string but that was extremely limited.
I have written an open source project, Dynamic Expresso, that can convert text expression written using a C# syntax into delegates (or expression tree). Expressions are parsed and transformed into Expression Trees without using compilation or reflection.
You can write something like:
var interpreter = new Interpreter();
var result = interpreter.Eval("8 / 2 + 2");
or
var interpreter = new Interpreter()
.SetVariable("service", new ServiceExample());
string expression = "x > 4 ? service.SomeMethod() : service.AnotherMethod()";
Lambda parsedExpression = interpreter.Parse(expression,
new Parameter("x", typeof(int)));
parsedExpression.Invoke(5);
My work is based on Scott Gu article http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx .
or http://www.csscript.net/
Oleg was writing a good intro at code project
It doesn't handle exact C# syntax, but PowerShell is so well enmeshed with the .NET framework and is such a mature product, I think you would be unwise to ignore it as at least a possible solution. Most server products being put out by Microsoft are now supporting PowerShell for their scripting interface including Microsoft Exchange and Microsoft SQL Server.
I believe Mono has mint, an interpreter they use before implementing the JIT for a given platform. While the docs in the official site (e.g. Runtime) say it's just an intermediate state before consolidating the jitting VM, I'm pretty sure it was there the last time I compiled it on Linux. I can't quite check it right now, unfortunately, but maybe it's in the direction you want.
bungee# is the thing that you want, in a short time, bungee sharp will be an open source project in
http://www.crssoft.com/Services/Bungee
. you can create scripts with the same c# syntaxt. there is no assembly creation when you run the script, interpretation is done on the fly, so the performance is high. all the keywords are available like c#. I hope u will like it very much..
I faced the same problem. In one project I was looking to provide a generic way to specify conditions controlling when a certain letter has to be generated. In another project the conditions were controlling how cases were assigned to queues. In both of them The following solution worked perfectly:
The Language for the snippets - I chose JScript so that I do not have to worry about variable types.
The Compilation - yes it requires full trust, but you can place your code in a separate assembly and give it full trust. Do not forget to mark it with AllowPartiallyTrustedCaller attribute.
Number of code snippets - I treated every snippet as a method, not a class. This way multiple methods can be combined into a single assembly
Disk usage - I did all compilation in memory without saving the assembly to disk. It also helps if you need to reload it.
All of this works in production without any problems
Edit
Just to clarify 'snippet' - The conditions I am talking about are just boolean expressions. I programatically add additional text to turn it to methods and methods to compilable classes.
Also I can do the same with C# although I still think JScript is better for code snippets
And BTW my code is open source feel free to browse. Just keep in mind there is a lot of code there unrelated to this discussion. Let me know if you need help to locate the pieces concerning the topic
This one works really well
c# repl and interactive interpreter
Is Snippet Compiler something you looking for?

C# .net Mnemonics and use in general

I'm just starting out with C# and to me it seems like Microsoft Called their new system .Net because you have to use the Internet to look everything up to find useful functions and which class they stashed it in.
To me it seems nonsensical to require procedure/functions written and designed to stand alone ( non instantiated static objects) to have their class not also function as their namespace.
That is Why can't I use Write or WriteLine instead of Console.WriteLine ?
Then when I start to get used to the idea that the objects I am using ( like string) know how to perform operations I am used to using external functions to achieve ( like to upper, tolower, substring, etc) they change the rules with numbers, numbers don't know how to convert themselves from one numeric type to another for some reason, instead you have to invoke Convert class static functions to change a double to an int and Math class static functions to achieve rounding and truncating.. which quickly turns your simple( in other languages) statement to a gazillion character line in C#.
It also seems obsessed with strong typing which interferes somewhat with the thought process when I code. I understand that type safety reduces errors , but I think it also increases complexity, sometimes unnecessarily. It would be nice if you could choose context driven types when you wish without the explicit Casting or Converting or ToStringing that seems to be basic necessity in C# to get anything done.
So... Is it even possible to write meaningful code in notepad and use cl with out Internet access? What ref book would you use without recourse to autocomplete and Network access?
Any suggestions on smoothing the process towards grokking this language and using it more naturally?
I think you're suffering a bit from the fact that you've used to working in one way during some years, and now must take time to get yourself comfortable using / developing in a new platform.
I do not agree with you , that MS hasn't been consistent on the fact that a string knows how it should convert itself to another type, and other datatypes (like ints) do not.
This is not true, since strings do not know for themselves how they should be converted to another type as well. (You can use the Convert class to Convert types to other types).
It is however true that every type in .NET has a ToString() method, but, you should not rely on that method to convert whatever you have to a string.
I think you have never worked in an OO language before, and therefore, you're having some difficulties with the paradigm shift.
Think of it this way: it's all about responsabilities and behaviour. A class is (if it is well designed) responsible for doing one thing, and does this one thing good.
There is no excuse to use notepad to code a modern language. SharpDevelop or Visual C# Express provide the functionality to work with C# in a productive way.
And no, due to the complexity, not using the internet as a source of information is also not a good option.
You could buy a book that introduces you to the concepts of the language in a structured way, but to get up-to-date information, the internet is neccessary.
Yes, there are drawbacks in C#, like in any other language. I can only give you the advice to get used to the language. Many of the drawbacks become understandable after that, even if some of them don't become less annoying. I recommend that you ask clear, direct questions with example code if you want to know how some language constructs work or how you can solve specific problems more efficiently. That makes it easier to answer those questions.
For notepad, I have no useful advice, however I would advise you to use one of the free IDE's, Microsofts Express Editions, or Sharp Develop.
The IDE will speed the groking of the language, at which point, you can switch back to notepad.
Reading your post I was thinking that you worked mostly with C or dynamic languages previously. Maybe C# is just a wrong choice for you, there are IronPython, F# and a bunch of other languages that have necessary functionality (like functions outside of classes etc.)
I disagree with you about consistency. In fact there are small inconsistency between some components of .NET, but most part of FW is very consistent and predictable.
Strong typing is a huge factor in low defect count. Dynamic typing plays nice in small/intermediate projects (like scripts, etc). In more or less complex program dynamism can introduce a lot of complexity.
Regarding internet/autocomplete - I can hardly imagine any technology with size of .NET that doesn't require a lot of knowledge sources.
Programming in c# using notepad is like buying a ferrari to drive in dirt roads.
At least use Visual Studio Express Edition. For what you wrote I understand that you come from a non OO background, try to learn the OO concept and try to use it. You will eventually understand most design decisions made for .Net.
http://en.wikipedia.org/wiki/Object-oriented_programming
Oh boy where do i start with you(this will be a long post hahaha), well, lets go little by little:
"Microsoft called their system .NET because you have to use Intenet...", the reason why is called .NET is because the SUITE OF MICROSOFT LANGUAGUES(and now some other ones too like Phyton and Ruby, etc) CAN CALL ANY LIBRARY or DLLs, example you can "NET"(Network OR CALL) a DLL that was built in Visual Basic, F#, C++ from WITHIN C# or from any of those languagues you can also call(or ".NET") C# libraries. OK ONE DOWN!!!
NEXT ONE: "it seems nonsensical to require....to have their class not also function as their namespace", this is because a Namespace can have AS MANY CLASSES AS YOU WISH, and your question:
"That is Why can't I use Write or WriteLine instead of Console.WriteLine ?".
The reason is because: "Console"(System.Console hense the "Using" statement at the beginning of your program) Namespace is where "Write" and "WriteLine" LIVES!!(you can also FULLY qualify it (or "call It"). (all this seems to me that you need to study C# Syntax), ok NEXT:
"when I start to get used to the idea that the objects...", ok in simple words:
C# is a "Strongly Type-Safe language" so that SHOULD-MUST tell you what "you are getting in to" otherwise STAY WITH "WEAK or NO TYPE SAFE LANGUAGES" LIKE PHP or C , etc. this does NOT means is bad it just MEANS IS YOUR JOB TO MAKE SURE, as i tell my students: "IF YOU NEED AN INT THEN DEFINE AN INT INSTEAD LETTING THE COMPILER DO IT FOR YOU OTHERWISE YOU WILL HAVE A LOT OF BAD BUGS", or in other words do YOUR homework BEFORE DESIGNING A PIECE OF SOFTWARE.
Note: C# is IMPLICITY TYPE SAFE language SO IF YOU WANT YOU CAN RUN IT AS UNSAFE so from then it wiLL be your job to make sure, so dont complain later(for being lazy) when bugs arrive AT RUNTIME(and a lot of times when the customer is already using your crappy software).
...and last but not least : Whey do you wan to shoot yourself by using notepad? Studio Express is FREE, even the database SQL SERVER is FREE TOO!!, unless you work for a company I WILL ASK FOR PRO, ETC. all the "extra" stuff is for large companies, teams, etc, YOU CAN DO 99% OF THE STUFF WITH THE FREE VERSIONS(and you can still buy-update to full version once you want to scalate to Distributed Software or a Large Project, or if your software becomes a big hit, Example: if you need millions of queryes or hits PER SECOND from your database or 100 people are working on same project(code) but for the majority of times for 2 or 3 "normal" developers working at home or small office the FREE ONES ARE ENOuGH!!)
cherrsss!!! (PS: Software Developer since the 80's)

Looking for a configurable pretty printer for C# code

I work on a team with about 10 developers. Some of the developers have very exacting formatting needs. I would like to find a pretty printer that I could configure to these specifications and then add to the build processes. In this way no matter how badly other people mess up the format when it is pulled down from source control it will look acceptable.
The easiest solution is for the team lead to mandate a format and everyone use it. The VS defaults are pretty good.
Jeff Atwood did that to us here on Stack Overflow and while I rebelled at first, I got over it :) Makes everything much easier!
Coding standards are definitely something we have. The coding formatting I am talking about is imposed by a grizzled architect that is, lets say, set in his ways and extremely particular. Lets just pretend that we can not address the human factor. I was looking for a way to circumvent the whole human processes.
The visual studio defaults sadly do not address line breaks very well. I am just making this line chopping style up but....
ServiceLocator.Logger.WriteDefault(string.format("{0}{1}"
,foo
,bar)
,Logging.SuperDuper);
another example of formatting visual studio is not too hot at....
if( foo
&& ( bar
|| baz
|| apples
|| oranges)
&& IsFoo()
&& IsBar() ){
}
Visual studio does not play well at all will stuff like this. We are currently using ReSharper to allow for more granularity with formating but it sadly falls sort in many areas.
Don't get me wrong though coding standards are great. The goal of the pretty printer as part of the build process is to get 'perfect' looking code no matter how well people are paying attention or counting their spaces.
The edge cases around code formatting are very solvable since it is a well defined grammar.
As far as the VS defaults go I can only say: BSD style or die!
So all that brings me full circle back to: Is there a configurable pretty printer for C#? As much as lexical analysis and parsing fascinate I have about had my fill making a YAML C# tool chain.
Your issue was the primary intent for creating NArrange (beta). It allows configurable reformatting of C# code and you can use one common configuration file to be shared by the entire team. Since its focus is primarily on reordering members in classes and controlling regions, it is still lacking many necessary formatting options (especially formatting within member code lines).
The normal usage scenario is for each developer to run the tool prior to check-in. I'm not aware of any one running it is part of their build process, but there is no reason why you couldn't, since it is a command-line tool. One idea that I've contemplated is running NArrange on files as part of a pre-commit step. If the original file contents being checked in don't match the NArrange formatted output on the source repository server, then the developer didn't reformat to the rules and a check-in error can be raised.
For more information, see my CodeProject article on Using NArrange to Organize C# Code.
Update 2023-02-25: NArrange appears to have moved to Github. The NArrange site (referenced above) is no longer available although there are copies in web.archive.org
I second Jarrod's answer. If you have 2 developers with conflicting coding preferences, then get the rest of the team to vote, and then get the boss to back the majority decision.
Additionally, the problem with trying to automatically apply a pretty printer like that, is that there will always be exceptional cases where your blanket coding standard is not the best or most readable solution, and you will lose out by squashing them with an automated tool.
Coding Standards are just that, standards. They don't call them Coding Laws or Coding Rules, and there's a good reason for that.

Categories