C# Console? [closed] - c#

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Does anyone know if there is a c# Console app, similar to the Python or Ruby console? I know the whole "Compiled versus Interpreted" difference, but with C#'s reflection power I think it could be done.
UPDATE
Well, it only took about 200 lines, but I wrote a simple one...It works a lot like osql. You enter commands and then run them with go.
SharpConsole http://www.gfilter.net/junk/sharpconsole.jpg
If anyone wants it, let me know.

Given your mention of "C#'s reflection power", I am unsure whether you're looking for an interactive C# console for small code snippets of your own (à la Ruby's irb), or a means of interacting with an existing, compiled application currently running as a process.
In the former case:
Windows PowerShell might be your friend
Another candidate would be the C# shell
Finally, CSI, a Simple C# Interpreter

Found this on reddit: http://tirania.org/blog/archive/2008/Sep-08.html
Quote from the site:
The idea was simple: create an interactive C# shell by altering the compiler to generate and execute code dynamically as opposed to merely generating static code.

If you don't have to use the console, and just want a place to test some ad hoc C# snippets, then LinqPad is a good option. I find it very cool/easy to use.

I am not sure what you are looking for this application to accomplish. If it is just to try some code without having to create a project and all the overhead to just test an idea, then SnippetCompiler could be a good fit.
I just wanted to give you another option.

It appears Miguel De Icaza was stalking me:
http://tirania.org/blog/archive/2008/Sep-08.html

Google reveals a few efforts at this. One in particular illustrates why this is less straightforward than it might seem. http://www.codeproject.com/KB/cs/csi.aspx has a basic interpreter using .NET's built in ability to compile c# code. A key problem is that the author's approach creates a new mini .NET assembly for each interpreted line. C# may have the reflective power to have a python or ruby style console, but the .NET framework libraries are geared toward compiling C#, not dynamically interpreting it. If you are serious about this, you may want to look at http://www.paxscript.net/, which seems like a genuine attempt at interpreted C#.

I believe you are looking for Snippy =)

Related

Should I write tests before they will compile? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been trying to follow a loose TDD workflow for one of my open source projects. It's an API for other programmers to use.
As such, one key aspect as well as making the API "work" is also designing how it will be consumed. I've heard some people say that writing tests before they'll compile is a waste of time and prone to constant rewrite until the API is stable. I've also heard that it should follow a workflow like so:
Write the tests which won't compile
Make it compile
Make it green
I've been trying to follow this workflow, but I end up with some weird things. For instance, in my API I have these two methods:
Handles(string pattern); //had this one already
Handles(IPatternMatcher pattern); //needed this one
I needed to get the second form of the method added to my API. So, I ended up with a dead simple test like so:
public void Handles_SupportsIPatternMatcher()
{
var api=new MyAPI();
api.Handles(new TestPatternMatcher());
}
Which seems like a waste after it gets implemented.
Should I continue following this workflow, or are there ways to improve it? How do I keep from writing tests that basically just check for compiler errors? Since it's a publicly consumable API, should I worry about tests like this?
No.
Do not write code that tests whether the compiler is working. Those kind of tests make a lot of sense if you are using dynamic languages (or dynamic features in a static language), where they will actually tell you that you forgot something, or refactored something into a failing unit test.
The point of the unit test execution is to fail the build if it is in error. If you have a compiler error in your code, the build will already fail. There is no need to second-guess it.
I you use resharper you can create the empty Handles method which will get IPatternMatcher. TDD is powerfull thing, and you should continue trying. I was trying both of ways test before code and test after code, and I found that test before code is powerfull thing. You can debug code errors very quckly. And test is warranty that your code will work as you expect.

Dilemma between keeping my code with pure js + jQuery AJAX calls or getting rid of every client script and rewriting the code in .NET only [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've developed a website (jQuery + .NET/C#) and it's 90% ready. Before a publish it I decided to face the truth and I admitted to myself the code isn't totally hack-safe. To be honest it's barely hack-safe. It's because I've been practicing some bad web programming habits (like relying too much on client scripting instead shelling it into server-side).
To be more precise, I've being using too much jQuery I guess and now I see all my webmethods are exposed in .js files. I've minified and obfuscated but it doesn't prevent a determined cheater to get all my stuff. That's one point.
Other issue is the fact I have some webmethods that return a lot of data from my database. Not confidential data, but some nice data my system generates and I don't wanna any external website to call it and display it like it is their material.
One of solutions I thought about was to generate all html in server-side and return it to .js and then append it to his respective element (in this way I'd hide all the intelligence beyond it) but it doesn't solve all the problems I related above.
So my question is... do you guys think it's safer to rewrite everything using ASP.NET controls or is there any way to make it REAL SAFE using the code I have (like avoiding external callings to my webmethods)?
I know without looking to the code it's hard to make an opinion but it's huge! And it's all about what I said (too much client-scripting, little server-side).
Thanks in advance.
First of all, you can check on serverside, which domain is calling your backend -> deny for unallowed domains. (Check this ticket)
To reduce javascript magic, you can move the logic into backend as you said.
Maybe some tricks to save your javascript code ( Check this out )
If you want a totally hack-safe Site, then you will be disappointed. you can just make it the hardest possible.
This is easiest with sites processed server-sided, and then served to the client. but i would also recommend not moving all to the server, because after all the server will have to process each and every request you make to it.
I have experienced, that it is the "easiest" to make all data-serving and evaluation logic serversided and rendering, as well as easy processing logic client-sided. Thus combining the strong sides of both technologies at minimal security risk. e.g. after an AJAX-Call to serve some data (if you even want to do that) you can call render, update and processing logic client sided with the help of success: or failure:, as well as after: or similar keywords.
Try some new things out. if you move it all to one technology/process you will have to take the disadvantages of this process. split things up!

C# code generator [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Can someone recommend a simple c# code generator. I just looking something with methods like:
GenClass = CreateNewClass(AccessModifier,Name......)
GenClass.Add(new Method(AccessModifier,RetType,Name....){code=#"....."}
GenClass.Add(new Property(AccessModifier,Type, Name....)
...........
etc
and after creating all classes\methods and other members we call Code Generation function(where we can specific some parametrs)
Is there such opensource code generator?
Check out Using CodeDOM to generate CSharp (C#) and VB code.
You may want to have a look csscript that relies on CodeDOM.
It allows you to write things like:
var PrintSum = CSScript.LoadMethod(
#"public static void PrintSum(int a, int b)
{
Console.WriteLine((a+b));
}")
.GetStaticMethod();
PrintSum(1, 2);
Be sure to read the doc, it's pretty detailed and you'll find you can do a lot more than what I just copied before.
T4 or Text Template Transformation Toolkit might be worth looking into.
Another option is to create your own simple generator, which contains functionality more suited for your situation than the CodeDOM. In a recent code generation project that's what I did, however I have encapsulated the code generation to make it possible to later transition to CodeDOM.
If you want to be able to generate a class given some arbitray string containing C# code, you need a C# compiler. At the moment the .Net framework does not ship with a compiler that you can pass snippets of C# to and get compiled code back. If you have more specific needs, you should specify exactly what you're looking to do.
Since you explicitly searching for an opensource code generator I suggest MyGeneration. Another, template based approach (which is not what you are looking for since want "GenClass.Add...." syntax rather than templates) would be Codesmith Tools it's really powerful but closed source.
take a look at my open source generator http://code.google.com/p/magicapps/

Code Samples for interview [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I recently applied for a developer position and the director there asked me to send some samples of code.
How should I approach this? Once, I sent a sample of code that I wrote for myself to a company and they didn't get back. This time, I want to be prepared and send appropriate samples. I want to know what I should send them, create a sample website/code it and send a link along with code files, or create a sample project, or some other approach.
I cannot send code that I have written for my previous and current employer, so I'm not sure what to send.
They asked for C#, HTML, CSS, JS, SProcs, triggers samples, so I thought: would it be nice if I create a project that includes all the above and send it to them, or should I send individual samples?
You've pretty much answered your own question. Why not create a project including all of the above? Small games are fun to write and you can demonstrate a lot of knowledge by creating one. Websites are good too, if you want to demonstrate things like good UI design and dynamic HTML and scripting knowledge.
It's essentially your portfolio to demonstrate what you're capable of, so apply all your knowledge. This includes not just what the program does but also how it does it -- good choice of algorithms, code architecture, proper naming of variables and appropriate comments, etc.
You can write code that's of just as high quality as what you'd create for an employer -- higher, in fact, since you have complete control over the methodology and standards used. Install one of the free revision control systems (git, mercurial, subversion etc), use bugzilla to track your bugs and todo list, and write a full suite of unit tests. Produce professional documentation and demo screenshots.
Yeah, that's a lot of work. But I can guarantee you that if such a project crossed my hiring desk, I'd have you in for an interview in a hot minute.
I've been in this situation before, and I usually just refuse to send them the code samples.
The reason is this: when I work for an employer, I'm working professionally, and the employer has exclusive rights to all the code. If I tried to copy the code and send it to another potential employer, I'm at risk of major intellectual property theft. On the other hand, if I create some code for my own use, it is by definition amateur code (even if produced by a professional), and doesn't have the same level of project management stricture, test stricture, etc., and is therefore not representative at all of my professional coding skills.
Companies that ask for this are effectively asking for the impossible. I find it best to point this out to them.
I'd take something I already worked on - preferably three-tier including sprocs, etc., and factor out anything of a sensitive nature. If it's something you wrote yourself then you will be comfortable discussing it and able to show the breadth of your knowledge - that's what will land you the job. A complete project shows that you know how everything fits together. One more thing: if they ask you where you go to find good code samples, do not immediately say Google: tell them you would look in their code base ;-)
Besides what you send them (a project, a website), I suggest you also give some thought as to what you want to convey with it, and give a written introduction to the sample: why you think it's an interesting piece of code? What does it showcase? What pieces are you proud of? What were the challenges?
They should be able to figure that out themselves, but there is no harm in helping people see what you want them to see...
WHen I intervoiew people I often ask them to give me some code. Usually I asked them to code infront of me though but I guess my point would be the same if the send it to me. I don't look at what they've done (the functionality) but how they've done it. What design principles guide their work. How tidy is the code. What's their test strategy. Have they used any patterns and if so are they used in a well thought way. Depending on the language I'd look for specific aspects of the language. In c++ I'd love to see them be capable of using template specialization elegantly (E.g. for traits/policies) in c#3.0 I'd look for propper use of lambda expressions, generics, LINQ I'd be looking for both correct use as well as over use.
Hope it gave you an idea of what kind of scrutiny you might be put through

Switching from C# to C++. Any must-reads? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm trying to find a least-resistance path from C# to C++, and while I feel I handle C# pretty well after two solid years, I'm still not sure I've gotten the "groove" of C++, despite numerous attempts.
Are there any particular books or websites that might be suitable for this transition?
About two years ago, I made the switch from C# to C++ (after 10 years of writing java). The most useful book for me was Bruce Eckel's Thinking in C++ [AMZN]. You can also read the book online at Eckel's website. It's a well-written book--the kind you can read in bed--that's also useful as a keyboard-side reference. It assumes a significant level of comfort with OO and general programming concepts.
Stroustrup [AMZN] is invaluable as a reference, but basically impenetrable unless you're trying to answer a very specific question--and even then, it's a struggle. I haven't cracked my K&R [AMZN] in a few years. I don't think it's got much value as a C++ reference. Myers' Effective C++ [AMZN] (and, once you get there, Effective STL [AMZN]) are fantastic books. They're very specific, though (e.g., "36. Design functor classes for pass-by-value"), and hence not as useful as Eckel for making the transition.
My experience writing C++ after many years writing managed languages has been great. C++ is a hundred times more expressive than C#, and extremely satisfying to write--where it's warranted. On the other hand, on the rare occasions when I still get to write C#, I'm always amazed by how quickly and succinctly I can get things done.
Anyway, Eckel's Effective C++ can help you make the transition. There's a second volume that's good, but not as good. Stick with the original.
Good luck!
I recommend The C++ Programming language by Bjarne Stroustrup. It's not a suitable book for new programmers, but I found it quite effective as programmer who was experienced in other languages and didn't want to waste too much time with learning how while loops work. It's a dense but quite comprehensive book.
I suggest you to read The C++ Programming Language book (written by Bjarne Stroustrup). It may not be the best book to begin with, but it is definitely on you should read, sooner or later.
Anything written by Meyers, recommended by same, or written by Sutter.
Accelerated C++ by Koenig (Edit: and Moo.)
They are fundamentally very different beasts so there is no least resistance path between. However I recommend you to read http://www.phpcompiler.org/doc/virtualinheritance.html beforehand in case you ever need a non-trivial inheritance. It can save you a few headaches.
The C++ Programming Language by Bjarne Stroustrup is a must read. Effective C++ (Scott Meyers) is another book I found helpful.
And to balance all this, read the C++ FQA ( http://yosefk.com/c++fqa/ ) - while not a book, it's a valuable resource, and I wish I had access to it when I was getting started with C++. Just don't let it discourage you.
I found Lippman et al's "C++ Primer: 4th edition" to be excellent. It emphasizes STL usage, best practices, and auto_ptr usage from the very first. I went from a Java position to a C++ assignment, and it was really excellent.
As a pure reference, Josuttis's "The C++ Standard Library" was STL at its best (and worst...the guy really doesn't pull punches)
Lastly, Meyer's Effective C++, as others have said is a must-read for the "gotchas" inherent in C++
This is a list of books that are recommended by the folks over in #C++ EFNet: http://rafb.net/efnet_cpp/books/
I'd consider [K&R](http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)) a prerequisite for C++. Perhaps the best thing about C++ is that it's a better C.
And of course, Stroustrup (as suggested by Mladen Jankovic) is a must read.
My two standard books are "Object-Oriented Programming in C++", Third Edition, by Robert LaFore, published by The Waite Group, and "C++ from the Ground Up" by Herbert Shildt, published by Osborne McGraw-Hill.
You should read one of the other books posted, but then also The Design & Evolution of C++. It helps you to get inside the head of what the language is trying to do.

Categories

Resources