<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Areeb</title>
    <description>The latest articles on DEV Community by Areeb (@zainjer).</description>
    <link>https://dev.to/zainjer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F339374%2Fa70ca071-b91e-4a41-b59e-0b5f96044850.jpeg</url>
      <title>DEV Community: Areeb</title>
      <link>https://dev.to/zainjer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zainjer"/>
    <language>en</language>
    <item>
      <title>An Engineer's Dilemma</title>
      <dc:creator>Areeb</dc:creator>
      <pubDate>Tue, 04 May 2021 21:35:45 +0000</pubDate>
      <link>https://dev.to/zainjer/an-engineer-s-dilemma-5eam</link>
      <guid>https://dev.to/zainjer/an-engineer-s-dilemma-5eam</guid>
      <description>&lt;p&gt;Food for thought..&lt;/p&gt;

&lt;p&gt;An Engineer’s Dilemma &lt;/p&gt;




&lt;p&gt;I believe there are two fundamentally different ways our brains can think and process thought progression,  &lt;/p&gt;

&lt;p&gt;What to do? and&lt;br&gt;
How to do it? &lt;/p&gt;

&lt;p&gt;As an engineer I am more accustomed to the later, my brain is wired to think about how to do things, how to fix stuff, how to solve problems. &lt;/p&gt;

&lt;p&gt;While that is well and good, (infact it is very respectable)&lt;br&gt;
I believe this particular thought process may have an inherent flaw. And I will try to explain what I mean in this piece.&lt;/p&gt;

&lt;p&gt;Engineers are very capable problem solvers. Like for example, if you give, the challenging task of building a bridge to a capable Civil engineer, they will find the best possible solutions to build it, they will think about each and everything that goes into the process, they will make great technical decisions, and deliver incredible results.  &lt;/p&gt;

&lt;p&gt;If you give a software engineer a challenging product to build, they will think, they will design, they will find various 3rd Party implementations to help solve the given problem.&lt;br&gt;
It could be related to networking, it could be related to data, whatever it may be, no matter how difficult it might be, or how impossible sounding it could be, engineers will always find a way. &lt;/p&gt;




&lt;p&gt;And then there are people who think about ‘What to do?’ &lt;br&gt;
Usually these people aren’t engineers, they are managers, leaders, think tanks, they are people of great vision.  A great example of this category of people would be Steve Jobs. &lt;/p&gt;

&lt;p&gt;That man had a vision of pushing the entire computer industry into a completely new domain. The domain of thin client, lightweight, smart devices, which are always interconnect with each other.&lt;/p&gt;

&lt;p&gt;He had the vision of a world where almost everything could be done on a device that sits on the palm of your hand. But he didn’t always know how to do it, how it would work, what new technology needed to be developed, how will those ideas get realized. But he trusted his engineers to do all these things, while he provided them with a crystal clear Vision. And his engineers, they did deliver! &lt;/p&gt;

&lt;p&gt;The iPhone and all smart phones in general are a technological marvel. The phone that was once used only to communicate will people wirelessly, is so much more now. &lt;/p&gt;




&lt;p&gt;Alright, getting back to the point I was trying to make,&lt;/p&gt;

&lt;p&gt;There are Two modes of Thinking. [two domains of processing thoughts] &lt;/p&gt;

&lt;p&gt;They are..&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What to do? and &lt;/li&gt;
&lt;li&gt;How to do it? &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One cannot survive without the other, if you only have resources those who can think about ‘What to do?’ But none who know ‘How to Do it?’, nothing can be done. Every thought, every idea will be a fantasy, no matter how new, how innovative or ground breaking.&lt;/p&gt;

&lt;p&gt;On the other hand, if you only know How to do stuff, but don’t know what to do. Nothing could be made. &lt;br&gt;
Without vision, without innovative ideas and imagination, Engineers would not know how to harness the amazing tools that they possess. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For every solution there is, a problem needed to exist. &lt;br&gt;
For every Innovation there is, An Idea was behind it. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I have been haunted by this dilemma for a long time now. As an engineer, I can do a great many things but I lack the vision of what to do. &lt;/p&gt;

&lt;p&gt;Now it is indeed possible for a person to possess both of these thought processes, to have both the vision of what to do, and the skills/mind-set to actually do it.&lt;br&gt;
A good example of which are Designers. Most designers from various domains such as Graphics, Typeface, Illustration, Writing, Architecture and sculpting have this ability. They possess the ideas and vision, and they hold the tools to realize them into fruition. &lt;/p&gt;

&lt;p&gt;This is why I have a great respect for Designers. The creative people of this world. &lt;/p&gt;

&lt;p&gt;So in conclusion,&lt;br&gt;
I believe that the Ultimate Engineer is someone who has both &lt;em&gt;The Vision&lt;/em&gt; and &lt;em&gt;The Skill&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Personally I admit that I lack the Vision, the Ideas and the Innovation. And I am deeply concerned about this. I may be a great engineer, but I am not a visionary. &lt;br&gt;
Therefore, whenever I sit down to write some new software, a new project, or to make a great game, to create the next big thing, to solve a problem. I often find myself lost and frustrated. &lt;br&gt;
I have the tools, I have the skills, I have the technical knowledge and I know how to tackle problems, yet, I am unable to produce anything by myself Unless told what to do.  &lt;/p&gt;

&lt;p&gt;I believe this is dilemma, besides me, haunts many other engineers in the world too!   &lt;/p&gt;

&lt;p&gt;And I’d like to call you guys out, including myself, All of us who face this dilemma every day.&lt;/p&gt;

&lt;p&gt;We as a community, need to come together and learn this great ability of new thinking, of having visions and innovative ideas.&lt;/p&gt;

&lt;p&gt;When someone knows about all the extents, the technicalities, the governing laws, the restrictions and the possibilities within their respective domain (such civil engineering, chemical engineering, software engineering) their brain may end up creating a virtual wall because of that vast knowledge. A comfort zone. A barrier that dictates what is possible and what is not.  &lt;/p&gt;

&lt;p&gt;This is why children are so full of ideas. Their brains do not have such walls, they do not know those extents, their brains are elastic and full of colour.&lt;br&gt;
Alright so, what to do then…? What can we do as engineers to tap into that creativity, that world full of new ideas and new thinking? &lt;/p&gt;

&lt;p&gt;I have a proposal to that, and it is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Reading: We must Read, and not just those technical books, but the fictional ones as well. Get ourselves familiar with those wild imaginary creations that exist in those fictional worlds. And this includes not just reading books but also watching sci-fi movies or playing supernatural games.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Exploration: We must explore, not just our own domain/career but other’s as well. A lot of computer science techniques were inspired by nature and biology. Such as ‘neural networks’ and ‘natural selection’ algorithms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Communication: We must talk to kids, talk to people that know nothing about our domains. We could ask them about the problems we are trying to fix. Since they have no knowledge about the extents, barriers and laws of our domains, they will always end up giving us a creative, out of the box and maybe an absurd idea. The likes of which we never could have thought about before.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I once asked my mother how would I stack 3D models of Train wagons on virtual 3D train track (which so abstract it’s basically a curved line). &lt;br&gt;
And she said, ‘Son, Why don’t you use magnets?’  &lt;/p&gt;

&lt;p&gt;That hit me quite hard :D, albeit it wasn’t possible to use magnets, it did give me a wonderful set of ideas on how to solve my problem.&lt;/p&gt;

&lt;p&gt;I believe all of us should strive to keep evolving. Once we become great engineers, the next step in our evolution shall be to become great thinkers, visionaries, people with colourful &amp;amp; wild imagination. &lt;/p&gt;

&lt;p&gt;Thank you for reading &lt;/p&gt;




&lt;p&gt;Alright, that concludes my long ‘Food for thought;&lt;/p&gt;

&lt;p&gt;What do you think?&lt;/p&gt;

</description>
      <category>leadership</category>
      <category>architecture</category>
      <category>psychology</category>
      <category>vison</category>
    </item>
    <item>
      <title>An Honest opinion on Java &amp; Its ecosystem.</title>
      <dc:creator>Areeb</dc:creator>
      <pubDate>Sun, 28 Mar 2021 21:48:23 +0000</pubDate>
      <link>https://dev.to/zainjer/an-honest-opinion-on-java-its-ecosystem-1g6</link>
      <guid>https://dev.to/zainjer/an-honest-opinion-on-java-its-ecosystem-1g6</guid>
      <description>&lt;p&gt;Alright, I admit C# is my primary language. &lt;br&gt;
but this is my unbiased opinion on Java and the ecosystem surrounding it. &lt;/p&gt;

&lt;p&gt;so it goes like this~&lt;/p&gt;

&lt;p&gt;I used to bash java quite a lot, pointing out all its weaknesses, &lt;br&gt;
such as java doesn't have properties. it doesn't natively have events, it doesn't have structs, no operator overloading, and until java 10 there was no inference so no 'var' either. All of which C# has! &lt;/p&gt;

&lt;p&gt;Until a while ago, I used to bash java quite a lot for not having LINQ and 'var' and enums&lt;br&gt;
And yet I write java quite a lot! especially when I'm writing android apps, but for other things too! Heck, my first coding project was also in java!&lt;br&gt;
So this Friday night, due to the urgency of delivery I had to write Java for 8 hours straight. &lt;/p&gt;

&lt;p&gt;and guess what I discovered? STREAMS! &lt;/p&gt;

&lt;p&gt;apparently, Java 8 introduced Streams! and I had no clue about it!&lt;br&gt;&lt;br&gt;
for those of you who don't know, Streams is java's Implementation of LINQ. &lt;/p&gt;

&lt;p&gt;Also, I discovered Java 10 has type inference so 'var' is a thing now in java!! &lt;br&gt;
(I can't believe how outdated I've been and trust me there's a reason for that.)&lt;/p&gt;

&lt;p&gt;Discovering these 2 things changed my mindset a lot!&lt;br&gt;
did you know java has always had checked exceptions and C# does not!?&lt;br&gt;
I admit It's a feature I quite miss in C#!&lt;br&gt;
Yes, it doesn't have structs or properties, etc but boi is it elegant!?&lt;/p&gt;

&lt;p&gt;I think Java will, by design, impose on you to write more robust applications. Whereas in .NET world, it is mostly left up to the developer to be careful. [Now some devs like this imposing &lt;br&gt;
and restrictions where others might prefer freedom]&lt;br&gt;
Albeit, both of them are quite secure but clearly, Java might have an ever so slight edge here!&lt;/p&gt;

&lt;p&gt;So, why do big organizations prefer java? &lt;br&gt;
Yes, Maybe I get it now. 😃&lt;/p&gt;

&lt;p&gt;What hurts me the most is that... in most of the code examples you see online, these advanced features aren't always used.. heck I think if a fairly new java developer sees 'var' written all over a codebase they'll go mad! 😂 and streams? what are streams? Java devs love their For loop! in fact, even foreach loops are quite rare in the java world. (and there maybe a reason for that, For loop, is much more optimized!)&lt;/p&gt;

&lt;p&gt;But these are good features! I'll go as far as claiming that they are awesome features!  it hurts me to my core when I write Android apps and notice, there is no usage of enums almost anywhere in the android API! and that's fair because android was written ages ago. What triggers me the most is when I have to use constants every time I have to use the 'Activity for Results' feature in android&lt;br&gt;
eg:  int  PICK_IMAGE_FROM_GALLERY = 3000 &lt;/p&gt;

&lt;p&gt;Bro that is madness! and yet people all over the world have come to accept it. and by contrast even me :D &lt;/p&gt;

&lt;p&gt;Java is lacking native implementation of events too! if only it had events &amp;amp; delegates like C#...&lt;br&gt;&lt;br&gt;
(hey java language designers if you guys are reading this, you gotta add events! and if you already have or it is in the works, do let me know 😃) &lt;/p&gt;

&lt;p&gt;Anyways I think I know what might be the biggest flaw in the Java ecosystem &lt;/p&gt;

&lt;p&gt;THE DOCUMENTATION!! &lt;/p&gt;

&lt;p&gt;The jarring unhelpful documentation on the Oracle website. it is stupid! it looks old! straight from 2007.&lt;/p&gt;

&lt;p&gt;Also, it doesn't always have example snippets. if you go look up a relatively uncommon language feature or API Method, you'll find a boring function definition, declaration, arguments, which package it belongs to and that's it! &lt;br&gt;
I think that's absurd. don't you think it's absurd? no code snippets?&lt;/p&gt;

&lt;p&gt;Therefore we the developers have to rely heavily on forums like StackOverflow or other programming websites like TutorialsPoint.. sometimes they do help with nice code examples highlighting the feature but other times, they aren't that helpful either.&lt;br&gt;
I mean seriously go evaluate Microsoft docs on C# with oracle docs on Java.. there's no comparison! &lt;br&gt;
(don't believe me? Go check : &lt;a href="https://docs.oracle.com/en/java/javase/16/docs/api/index.html"&gt;Oracle&lt;/a&gt; &lt;a href="https://docs.microsoft.com/en-us/dotnet/csharp/"&gt;Microsoft&lt;/a&gt; )&lt;/p&gt;

&lt;p&gt;MS Docs are beautiful! heck, they even have a 'dark mode! omg, the dark mode 😂 we devs go crazy for the dark mode&lt;br&gt;
what about Oracle docs? like I said, straight from 2007. there was no dark mode concept back in 2007 was there? &lt;br&gt;
So, what I am saying is, Java is Amazing! but it suffers a lot from aging documentation.  mostly old docs and old tutorials. which do not highlight the hot new features like streams and var and enums&lt;br&gt;
Now people go about saying Java is beginning to get old and it'll be replaced with Kotlin and I Disagree. Because even if that is true. It won't just replace it right away, not until at least many many many years from now!   &lt;/p&gt;

&lt;p&gt;I mean Scala tried that? didn't it? what happened there? Java is still ruling all over the JVM Ecosystem. although I do admit Scala is quite different from Java, it is Functional first where Java is object-oriented.&lt;/p&gt;

&lt;p&gt;Now finally.. there's this one thing that triggers me more than anything within the Java world and I mean "anything". And that is obtaining the JDK&lt;br&gt;
Why the hell is so hard to get JDK???? &lt;br&gt;
I mean if I need the JDK, a simple Google search will point to Oracle's website, I go there and I find the JDK version I need. relatively easy so far, but then, to download it, I have to sign up.&lt;br&gt;
WHAT? WHY?  why would I make an account on oracle and then deal with their email junk every week, just to freaking download the JDK!?  mind you Java has been open source from Day 1!!!&lt;br&gt;&lt;br&gt;
unlike C# which became open source very recently in 2015&lt;br&gt;&lt;br&gt;
So, I get frustrated and switch to the second website on google's search results. it points me to the OpenJDK website. I find the JDK there and hit download. but surprise surprise they give links to implementations of JDK from other sites!&lt;br&gt;&lt;br&gt;
Among those sites, there's that bloody oracle one but then there's also a link to Red Hat's website. &lt;/p&gt;

&lt;p&gt;Now RedHat is amazing. They are truly one of the pioneers among open source companies in the world.&lt;br&gt;&lt;br&gt;
So I go, alright! I'll download it from there then! &lt;br&gt;
I click that link, find the JDK version I'm looking for, and guess what? I have to sign up there as well. (dramatic pause) &lt;br&gt;
Now that is just sad...&lt;/p&gt;

&lt;p&gt;And to hell with that! What is wrong with these people?&lt;/p&gt;

&lt;p&gt;Finally, I give in and I install Chocolatey. (it's like apt-get but for windows. I think it is the first widely accepted and used package manager for windows)&lt;br&gt;&lt;br&gt;
and so, after that, I have to write a simple command in PowerShell&lt;br&gt;
 eg: choco install jdk-1.8 &lt;br&gt;
and I'm done. &lt;br&gt;
(if you are a C# developer, you'll know how easy it is to get the .Net SDK, just 2-3 clicks, no signing up and you are finished)&lt;/p&gt;

&lt;p&gt;To conclude my long rant; Java is a great programming language.  It is beautiful it is robust and it has (in my opinion) the best IDE in the world, JetBrains infamous 'IntelliJ IDEA', Java has a very helpful community, a vast and diverse ecosystem&lt;br&gt;
and all of this is coming from a C# developer.&lt;/p&gt;

&lt;p&gt;But we need to update the docs! the code examples! the APIs!&lt;br&gt;
we need to make getting the JDK easier!  &lt;/p&gt;

&lt;p&gt;All in all, Java is heading in a good direction, its popularity may have suffered a bit recently but that won't make java go away. it is currently, and has been for a decade, among the top 10 languages in the world! &lt;/p&gt;

&lt;p&gt;I do use java on a regular basis and I will continue to do so in the future as well.&lt;/p&gt;

&lt;p&gt;To all the awesome Java devs out there, You have my respect!&lt;br&gt;
Kind regards,&lt;br&gt;
&lt;a class="comment-mentioned-user" href="https://dev.to/zainjer"&gt;@zainjer&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>java</category>
      <category>csharp</category>
      <category>programming</category>
    </item>
    <item>
      <title>Say NO to public variables! (c#) </title>
      <dc:creator>Areeb</dc:creator>
      <pubDate>Sat, 28 Nov 2020 21:22:40 +0000</pubDate>
      <link>https://dev.to/zainjer/what-are-properties-in-c-and-how-to-use-them-1927</link>
      <guid>https://dev.to/zainjer/what-are-properties-in-c-and-how-to-use-them-1927</guid>
      <description>&lt;h1&gt;
  
  
  What are Properties in C# and, how to use them?
&lt;/h1&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;While writing software, I follow a simple rule.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;#1:&lt;/strong&gt; There should be NO public variables in a class. Only private ones are allowed. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  But Why do I follow that rule?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Please bear with me for a minute while I explain...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Okay, let's start by assuming (for now) that you are following this rule, and you do not use any public variables/fields in your classes. &lt;/p&gt;

&lt;p&gt;But now, immediately afterwards, you will face an obvious problem...&lt;/p&gt;

&lt;p&gt;How to access or manipulate an object’s fields from outside its class? Or &lt;br&gt;
How will you read the members of a class from anywhere else other than itself?&lt;/p&gt;
&lt;h4&gt;
  
  
  Use Methods!
&lt;/h4&gt;

&lt;p&gt;Java does it and almost every other OOP language encourages it!&lt;/p&gt;

&lt;p&gt;For example, we have a field ‘score’ in a class Player:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
     private float score;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since it is private, only the ‘Player’ class can manipulate it. But what if you wanted to access it from an outside class?&lt;/p&gt;

&lt;p&gt;You have to write &lt;em&gt;Get&lt;/em&gt; and &lt;em&gt;Set&lt;/em&gt; methods like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
     private float score;
     public void SetScore(float value){
         score = value;
     }
     public float GetScore(){
         return score;
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  But Why?
&lt;/h3&gt;

&lt;p&gt;A sensible question would be, why should we go through all the trouble of writing accessor and mutator (Getter &amp;amp; Setter) methods like these? &lt;br&gt;
Why not just make our fields ‘public’ and access them directly?&lt;/p&gt;

&lt;p&gt;The answer to that is in &lt;strong&gt;Better Control&lt;/strong&gt; over information.&lt;/p&gt;

&lt;p&gt;Or in OOP terms, It allows a combination of powerful encapsulation and abstraction.  &lt;/p&gt;

&lt;p&gt;For example, you want to access the ‘score’ field from some outside class (such as HighScoreManager), but you don’t want any outside class to modify its value because you are calculating the score based on some behavior internally.&lt;br&gt;
What will you do? How will you prevent some outside class to modify its value?&lt;/p&gt;

&lt;p&gt;If the ‘score’ field is public, any other object can easily access it but also modify its value.&lt;/p&gt;

&lt;p&gt;This is why having Getter and Setter methods can help you! &lt;br&gt;
If you don’t others to manipulate a field’s value, Only write its Getter and don’t write its Setter method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
     private float score;

     public float GetScore(){
         return score;
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The other feature you will obtain from using Getter Setters is that you can &lt;strong&gt;Observe&lt;/strong&gt; and &lt;strong&gt;prep&lt;/strong&gt; the values before they are accessed or mutated.&lt;/p&gt;

&lt;p&gt;For example, you are keeping track of the score in the ‘float’ type with 5 decimal points precision, but the outside classes require a rounded-off value You can simply prep the value before sending it off~&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
     private float score;
     public float GetScore(){
         float value = (float)Math.Round(score,2);
        return value;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, you might want to do a certain action, every time a field is mutated or modified by some outside class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void SetScore(float value){
        UpdateStats();            
        score = value;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I am calling a method every time an outside class modifies the ‘score’ field.&lt;/p&gt;

&lt;h5&gt;
  
  
  Alright, now we can grasp why...
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Getters &amp;amp; Setters are important.&lt;/li&gt;
&lt;li&gt;Why we should always make our fields private. And use Getter Setters to expose them to the outside world. &lt;/li&gt;
&lt;li&gt;How we can prevent others from modifying our fields by only giving them accessors (Getter methods) and no mutators (Setter methods).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Now let's talk about Properties
&lt;/h2&gt;

&lt;p&gt;Assuming that you have multiple fields in a single class, wouldn’t it mean that you will have to write a lot of boilerplate code for every field you want to expose?&lt;/p&gt;

&lt;p&gt;For example, if you have 5 fields, and you need to access at least 3 of them from outside that class, the overall footprint of that class will grow linearly as well.  &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
    private float score;
    private int id;
    private string name;
    private string[] powers;
    private Vector3 position;
    public float GetScore(){
        return score;
    }
    public void SetScore(float value){
        score = value;
    }   
    public string[] GetPowers(){
        return powers;
    }
    public void SetPowers(string[] powers){
        this.powers = powers;
    }
    public Vector3 GetPosition(){
        return position;
    }

    public void SetPosition(Vector3 position){
        this.position = position;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here for each field which we needed to expose, we wrote two methods. So for 3 fields, we had to write 6 methods.&lt;/p&gt;

&lt;p&gt;Now, most languages (including Java) are stuck with a messy solution like this, But C# provides a very elegant solution called: &lt;strong&gt;Properties&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using properties is very elegant!
&lt;/h2&gt;

&lt;p&gt;when compared to explicitly implementing separate Getter &amp;amp; Setter methods. &lt;/p&gt;

&lt;p&gt;Here is an example of the very same code from above, but with the use of Properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
    public float Score {get; set;}
    private int id;
    private string name;
    public string[] Powers {get; set;}
    public Vector3 Position {get; set;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you notice the difference? The overall footprint of our class is much smaller now! &lt;/p&gt;

&lt;p&gt;In case you need a Property to only be accessed but not mutated by any outside class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Player {
    public float Score {get; private set;}
    private int id;
    private string name;
    public string[] Powers {get; set;}
    public Vector3 Position {get; set;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I added a ‘private’ access modifier before the ‘set’. &lt;br&gt;
Thus, only the Player class can mutate this property now and it’s impossible to be mutated by the outside world.&lt;/p&gt;

&lt;p&gt;There are also a few other changes you might have noticed, The properties I needed to expose are now set to ’public’.&lt;/p&gt;

&lt;p&gt;I have also changed their names to start with a Capital letter now, and that is because they aren’t considered to be just &lt;em&gt;fields&lt;/em&gt; anymore! They are now considered &lt;em&gt;properties&lt;/em&gt;. &lt;br&gt;
Therefore they must follow the naming convention of Properties instead of fields.&lt;/p&gt;

&lt;p&gt;Now assuming you might need to prep the values before accessing or mutating them, how can you do that using properties?&lt;br&gt;
Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public float Score { 
        get{
            float value = (float)Math.Round(Score,2);
            return value;
        } 
        private set{
            UpdateStats();                
            Score = value;
        }        
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I have extended the getter &amp;amp; setter of the ‘Score’ property so that it preps the value before accessing or mutating it.&lt;/p&gt;

&lt;p&gt;Another cool feature of using properties over explicit Getter Setter methods is that you can assign values to properties just like a field. For example instead of using methods like this:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void MyMethod(){
Player obj = new Player();  

      //Getting the value
      float myScore = obj.GetScore();

      //Setting the value
      obj.SetScore(10);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an elegant solution:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void MyMethod(){
        Player obj = new Player();

        //Getting the value
        float myScore = obj.Score;

        //Setting the value
        obj.Score = 10;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like how we assign or extract values from a variable or field!&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;This is my first article on this platform! I will greatly appreciate your feedback &amp;amp; criticism. 😁&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reach me out at &lt;a href="https://github.com/zainjer"&gt;@Zainjer&lt;/a&gt; &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>csharp</category>
      <category>programming</category>
      <category>properties</category>
    </item>
  </channel>
</rss>
