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?

Carbon
  • 181

3 Answers3

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.

Telastyn
  • 110,259
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.
RubberDuck
  • 9,021
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.