Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have recently been more concerned about the way I write my code. After reading a few books on design patterns (and overzealous implementation of them, I'm sure) I have shifted my thinking greatly toward encapsulating that which change. I tend to notice that I write less interfaces and more method-oriented code, where I love to spruce life into old classes with predicates, actions and other delegate tasks. I tend to think that it's often the actions that change, so I encapsulate those. I even often, although not always, break down interfaces to a single method, and then I prefer to use a delegate for the task instead of forcing client code to create a new class.

So I guess it then hit me. Should I be doing functional programming instead?
Edit: I may have a misconception about functional programming.

Currently my language of choice is C#, and I come from a C++ background. I work as a game developer but I am currently unemployed.

I have a great passion for architecture. My virtues are clean, flexible, reusable and maintainable code. I don't know if I have been poisoned by these ways or if it is for the better. Am I having a refactoring fever or should I move on? I understand this might be a question about "use the right tool for the job", but I'd like to hear your thoughts.

Should I pick up a functional language? One of my fear factors is to leave the comfort of Visual Studio.

share|improve this question
    
You can try F# if leaving Visual Studio is a deal-breaker. –  Anna Lear Mar 12 '11 at 22:13
    
It's not a deal-breaker. I just haven't tried many other alternatives. I guess I got some fear against working without intellisense, refactoring or similar tools and have this conception that you end up writing code in a plain text editor again. –  Statement Mar 12 '11 at 22:15
    
I am currently unemployed ... should not this be the first thing to fix? –  Job Mar 13 '11 at 3:03
    
I would try to work without VS for a little while. You might find that working in a very minimalist way might be fun. –  Zachary K Mar 13 '11 at 10:52
    
@Job, yes, but I have been struck with a series of quite bad events recently :) I damaged my foot (well I don't code with my foot, but, still...) just recently after leaving my old job in search for a new one. –  Statement Mar 15 '11 at 17:37

6 Answers 6

up vote 5 down vote accepted

YES

Learning new stuff should be fun. And learning a new way to program should make you a better programmer. Check one of Haskell or Erlang, both are functional but they are very different. If you pick Haskell go find a few talks by "Simon Payton Jones" on youtube or podcasts. The guy is a great speaker.

share|improve this answer
    
Thanks for the tip! –  Statement Mar 15 '11 at 17:31
1  
I chose this answer of many reasons. @Zachary K says it might be fun to step out of the box of a well known place and have another perspective. I shouldn't be afraid to try something new. It's not the end of days. Haskell is a language that has caught my attention in various discussions a couple of times before. I don't know if I need a functional language but as @Toby Allen says it's a great way of seeing how other ways work and I agree on this after trying out some UnrealScript. @ammoQ missed the point a bit but I hadn't a very good definition of my question. I still get his concerns. –  Statement Mar 15 '11 at 17:45
    
Glad to help. Have fun –  Zachary K Mar 16 '11 at 7:24

Holy * * * *. There is no silver bullet. Step down. Relax, take a deep breath.

Just because you have a tool in your toolbox, it doesn't mean you are bound to use it. Concentrate on the task at hand, i.e. writing a program that works, and refactor when code smells bad. Don't encapsulate and abstract every little detail just because it might change some day in the future. IMO it's really much better to start straight forward, KISS & YAGNI, and react to changing requirements when they actually change.

I don't think anyone here can tell you whether or not a functional language is better suited for your needs. Because you didn't tell us what it is that you are working on.

share|improve this answer
    
Well, I ain't working on anything in particular right now. I'm between jobs. I am/was a game developer. –  Statement Mar 12 '11 at 22:19
3  
This is a dangerous situation regarding overengineering. No deadline, no backlog, just too much time to get obsessed with details. –  user281377 Mar 12 '11 at 22:28
    
(A lot of guesswork ahead since I have no clear picture in my mind) I guess my "needs" were more reflected in the way I prefer to write code. I don't know a great deal about functional programming, and I guess the name might tricked me a bit. I am just feeling that my preference is not as much object oriented as I thought. So maybe I should enjoy working in another paradigm? –  Statement Mar 12 '11 at 22:33
    
Yes, I guess it's the case. I am in a phase of learning right now so that is why I explore the possibilities of writing in particular ways. At work, one had often no time to write such code, and you have to respect the code of conduct and maintain a consistent style among developers. –  Statement Mar 12 '11 at 22:35
2  
It's absolutely ok when you try every tool at hand now that you are between jobs, but I'm afraid we can't tell you whether or not the shoe fits. –  user281377 Mar 12 '11 at 22:38

You can pick up F#. It is .NET functional language, which will allow you to use Visual Studio and reuse a lot of your .NET knowledge. It's assemblies of course integrate with C# assemblies seamlessly (allowing you to easily combine C#, C++/CLI and F# in one project). F# support comes with VS Pro or better, I'm not sure whether it is enabled by default though.

share|improve this answer
    
I think there's an addon for F# in VS2008, but it is default in VS2010. –  apoorv020 Mar 13 '11 at 6:08
    
F# works even with a free VS Shell. –  SK-logic Mar 13 '11 at 11:17

IMO, it's well worth trying out a functional language. Even if you never use it directly in a released product, learning it will almost certainly help give a somewhat different outlook/viewpoint on programming. Even if you end up continuing to do all your "real" coding in C#, chances are pretty fair that it'll help you improve the code you do write in C#.

As others have mentioned, the obvious choice for somebody accustomed to Visual Studio is F#, which is basically an Ocaml/Caml/ML derivative. IMO, that was a good choice on the part of Microsoft for introducing people to functional programming -- it's a full-fledged functional language, but doesn't have nearly as foreign a syntax as some do (e.g., while Lisp-based languages do have real advantages, beginners almost always find it difficult to read).

share|improve this answer

Yes, you should.

If you choose a pure one, like Haskell, you'll learn not only a new language, but a new way of thinking. This can help you later in your proceural/OO work, too.

F#, on the other hand, is not pure, and so you can easily miss what is important in functional programming. Yóu can, so to speak, continue writing procedural programs that mutate a variable here, perform some side effects there, just in F# syntax.

share|improve this answer
    
I actually got started at tryhaskell.org :) It's exciting to learn new things. –  Statement Mar 31 '11 at 17:59

If you are already using c# you don't need a new language - with the combination of extension methods, lambdas and the generic Func/Action types it is fairly easy to write functional code in C# - that way you can use a functional style in the algorithms where it makes most sense without needing to change the entire application.

share|improve this answer
1  
You always need another language. Even if you never use it, it is a great learning experience to learn a new language. No one language has everything. –  Toby Allen Mar 13 '11 at 16:23
    
You always need to learn, but you don't always need to learn another language. The benefit comes from learning the concepts of functional programming rather than the language itself, and you can do that without leaving the familiar environment and changing the entire project. C# is good enough, and in practical terms there is a huge advantage to only having the functional code in the algorithms that actually benefit from it. –  Tom Clarkson Mar 13 '11 at 22:43
    
Yeah I guess my concern was more biased toward if there are languages better suited (syntactically) for working with methods/functions in the manner I find myself often working in while toying out this. C# offer lambda expressions and that is nice in itself but for example having a function return a value without any parameters yield code such as () => x, and maybe there are cleaner ways to go about. –  Statement Mar 15 '11 at 17:34
    
+1 @Toby. I just recently skimmed through UnrealScript reference and saw some interesting language solutions for working with states et.c. It carries over to C# in terms of thinking about the problem and they have a quite nice solution. So yes, I do believe you learn a great deal when you step out of your sandbox and pillage your neighbors for all the sand and toy you find :) –  Statement Mar 15 '11 at 17:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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