3

I'm primarily a Python/R developer. In those languages, the way I develop is to sketch out a data and class structure, write the methods and their tests in interactive mode, then refactor them up into class methods and properties and sort out the tests. Some friends are suggesting I learn C#. I don't do much work with complied/staticly typed languages.

Can I develop in an 'interactive mode' the same way in C# - that is, load in some sample data, write methods interactively to ensure they're working right, then push methods up to classes as they're completed? Or is this not a natural way to develop in a compiled language?

  • 2
    Unclear what help you need. Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it’s hard to tell what problem you are trying to solve or what aspect of your approach needs to be corrected or explained. See the How to Ask page for help clarifying this question. – gnat Jul 10 '15 at 0:50
  • 3
    @gnat: He's trying to figure out if you can do REPL-like development in C#. It can be done, but not in Visual Studio. – Robert Harvey Jul 10 '15 at 0:58
  • 2
    There is no C# REPL... yet – Dan Lyons Jul 10 '15 at 18:38
3

Can I develop in an 'interactive mode' the same way in C# - that is, load in some sample data, write methods interactively to ensure they're working right, then push methods up to classes as they're completed?

Not the same way. There isn't really such interactive tools for C# since the problems you're usually solving are large enough to make that unweildy (and the standard compilation model doesn't lend itself to it).

Or is this not a natural way to develop in a compiled language?

Every language has its quirks and idioms. I can't write C# code like I do C++, and I can't write JavaScript the same way as perl. You're going to need to adapt when learning a new language, and that sort of adaptation is the main benefit of learning different languages - you get a broader perspective of different ways of doing things.

All that said, you can and should do iterative development in C#. Smaller chunks of code are easier to reason about, easier to test, easier to debug. The mechanics of doing that though are likely to change due to the quirks of the language and the tools available.

1

The kind of iterative development you're speaking of is typically done via Unit Tests in C#.

  1. Add a Unit Test project to your solution.
  2. Add aUnit Test class to the test project.
  3. Define the public API you want to create.
  4. Write a test to exercise one of the class's members.
  5. Run the tests. It should fail.
  6. Implement the functionality.
  7. Run the tests. If green, great! If red, GoTo #6.
  8. Repeat.
  • 1
    That seems like an analogous approach. – Carbon Jul 10 '15 at 17:36
  • You're almost talking more about development in Visual Studio than you are development in C#. ;-) – Craig Jul 12 '15 at 2:50
  • I suppose so @Craig. Most of my work in VS is with C# and I rarely write C# outside of VS... I just wanted to add the practical answer here. The existing ones didn't address the actual workflow OP was looking for. – RubberDuck Jul 12 '15 at 2:52
  • @RubberDuck I think it's a useful answer. I definitely didn't mean what I said negatively, and most people doing C# development are going to be using some flavor of Visual Studio, and your test-first approach would obviously still work if developing with Notepad.exe and the command line compiler, just not automatically like what you can do with VS. ;-) – Craig Jul 12 '15 at 2:54
  • Yeah and since they released the Community edition not using it seems silly @Craig =;)- – RubberDuck Jul 12 '15 at 3:31
0

Whenever I have small code snippets that I'd like to test, I personally enjoy using .Net Fiddle.

Don't forget you can always spin up small projects like a C# console app to do fairly straightforward things. This may be especially necessary if you need to use third party libraries.

Not the answer you're looking for? Browse other questions tagged or ask your own question.