-6

Is the c# a functional or object oriented language?

I need to learn writing very good code using c#, but should I use C# primarily as a functional language or object orientated?

I'm confused should I use OOP coding style or functional coding style. or should I mix between them.

Jim G.
  • 15,141
  • 22
  • 103
  • 166
jobin
  • 1,119
  • 2
  • 12
  • 22
  • You should read this blog... http://www.c-sharpcorner.com/UploadFile/84c85b/object-oriented-programming-using-C-Sharp-net/ – sheshadri May 04 '15 at 09:35
  • @CarstenKönig finally, thank you, I forget the question and know I'm focusing to understand why they downvoted :( , if they mention why this will help me to enhance my questions next time – jobin May 04 '15 at 09:47
  • 2
    most likely it's because the question does not really fit here - on the one hand you are asking more or less for opinions and on the other side (as you can see) the only answer with upvotes(accepted) is basically a copy&paste job from wikipedia (so you could have found the information rather easy yourself) - but still it's rude to mass-downvote without giving any clue to newer members - but that's one problem with the popular tags (like C#) – Random Dev May 04 '15 at 09:51
  • 1
    In case you are interested in FP I would recommend looking into F#, Haskell, Scala, Clojure, ... - not only are those functional first (ok you could argue with Scala ;) ) - but the sub-communities here are much more friendly :D – Random Dev May 04 '15 at 09:53
  • 1
    thank you @CarstenKönig , all books and articles mention functional or object oriented language. and first time for me that I know these things known as "paradigm", and now I know this new term and I'll start my research on it. regardless they vote up or down, at the end the result very useful for me :) – jobin May 04 '15 at 10:05
  • You can go for using C# as a OOP language and by the time you are writing real good code, the language designers may have added enough elements to C#7 (or C#8 to) use it as a fully functional langauge as well; at least that's what they said they were looking at, at the latest Build conference.. – TaW May 04 '15 at 11:06

2 Answers2

2

From wikipedia:

C# is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines

So, in general, we can just use whichever paradigm suits our needs for the task at hand.

UPDATE: A couple of caveats have been highlighted by the comments below:

  • It is primarly intended to be "a simple, modern, general-purpose, object-oriented programming language" which means that the functional paradigm plays second fiddle to the object oriented one.
  • As a result some concepts considered important for functional programming are missing such as tail recursion
  • We can also change a mutable state via too many avenues to guarantee functional programming without side-effects. We therefore ought to excercise a little caution when using a functional paradigm not to alter state (for example by ensuring we are not changing an object in a LINQ Select statement)
Community
  • 1
  • 1
Stewart_R
  • 13,764
  • 11
  • 60
  • 106
  • multi-paradigm programming is new term for me, thank you I'll read about it – jobin May 04 '15 at 09:38
  • 2
    It should be said though that C# is primarily an object-oriented language. It allows too many access paths to mutable state to guarantee pure functional programming without side effects. You can certainly use the functional paradigm (see e.g. LINQ) but you always have to avoid these side effects (like changing an object in a `Select` statement). – Gert Arnold May 04 '15 at 10:04
  • 1
    @GertArnold, agree with you "The ECMA standard lists these design goals for C#:The C# language is intended to be a simple, modern, general-purpose, object-oriented programming language." this statement form wikipedia – jobin May 04 '15 at 10:09
  • 1
    it seem functional capabilities is subsidiary and the main design goal: C# is an object-oriented programming language – jobin May 04 '15 at 10:12
  • 1
    @jobin That's true. It also lacks some concepts that are a must-have for real functional languages, e.g. [tail recursion](http://stackoverflow.com/questions/491376/why-doesnt-net-c-optimize-for-tail-call-recursion). – Gert Arnold May 04 '15 at 10:13
-2

c# is an object oriented language.

SamY
  • 78
  • 10
  • may be your answer is correct, but any references or description on this subject. if it is object oriented language this does not prevent that C# also a functional language. also I need to know should I treat as oop or as functional and why? – jobin May 04 '15 at 10:16