Coding Conventions in Unity

  Рет қаралды 28,096

Infallible Code

Infallible Code

Күн бұрын

Пікірлер
@beardordie5308
@beardordie5308 4 жыл бұрын
Lol "There's three of us now!?" "You and I work together a lot." 😆👍
@subliminalcastillo2126
@subliminalcastillo2126 4 жыл бұрын
That part made me laugh my ass off hahaha
@IsmaelSerrada
@IsmaelSerrada 4 жыл бұрын
Changing to Rider IDE was one of the best choices I made as a programmer, saves time, suggest appropriate changes to my code, and let me set up other conventions that may not be the default ones. I like these videos, there is always room for improvement when coding in any type of workflow. Keep up the good work.
@josh_swanson
@josh_swanson 4 жыл бұрын
Damn, that skype video quality is next level!
@ewwitsantonio
@ewwitsantonio 4 жыл бұрын
Can you pitch shift Barles' voice down an octave and give him one of those technicolor hats with the propeller on top please thanks
@modiddymo
@modiddymo 4 жыл бұрын
ewwitsantonio he’s waiting to give those to Gnarles when he drops the mob coding episode
@mrgetrext297
@mrgetrext297 2 жыл бұрын
This video formatting is amazing, definitely earned my sub
@subliminalcastillo2126
@subliminalcastillo2126 4 жыл бұрын
What I do instead of copy and pasting code, is I retype the code & even modify it as I am going. This way I get a much more intimate experience with each part of the code, and can also understand it better as I'm figuring out how I should break it up, style, & rename all the pieces of it.
@CreativeSteve69
@CreativeSteve69 4 жыл бұрын
I have to say Infalilible Code I'm glad that I found your channel back in 2016 when I first got interested how GameDev works. I love how you bring sketch comedy format into something well through educational content. I learn a lot through this method please keep it up. :)
@faythe03
@faythe03 4 жыл бұрын
In the last couple of days I have been reading about the Microsoft coding conventions, so this video came out at the right time for me!
@TNTCProject
@TNTCProject 4 жыл бұрын
Love how you edit your videos. Good job!
@iercan1234
@iercan1234 3 жыл бұрын
watched this in 4K it saved my life
@EricKesterson
@EricKesterson 4 жыл бұрын
As you state in the video having a convention for your code at all is more important than worrying about which convention to use. I wanted to make an argument however for always prepending class member references with "this." (for example a variable declared as private float speed; would be referenced using this.speed. The reason I favor that approach is because "this" is a language feature that can only be interpreted in one way (the way the language interprets it). I've seen many different uses of "_" in unity code and you can find yourself confused when swapping between your own code, unity documentation, and downloaded / copied / tutorial code. Sometimes private members are prepended with "_", sometimes method arguments are prepended with it. I come from Java software development which is where I picked up this standard, however some of the Unity examples also use it (though the unity docs seem to be some of the most inconsistent styled code anywhere). Allowing an IDE such as Rider to provide formatting is also a good argument, however I have not yet switched to Rider myself. As for public vs private, personally I haven't actually found it to be extremely important to differentiate between them when reading through code, so I don't bother to differentiate their naming. To be clear, I do carefully consider what members should be public or private, but once that contract is established, I don't usually need to consider it any further, so I don't use a naming convention to keep them visually distinct. Knowing which variable is a member and which is a method argument has proven much more valuable to me. These approaches have done well for me as a hobbyist Unity developer for the past 5-ish years and as a software developer for the past 15. As stated in the video this will always be a divisive topic, and I don't intend to detract from valid arguments for other styles, just offer my own experience.
@fmproductions913
@fmproductions913 4 жыл бұрын
Important concept to cover to, and I like the brought up reasons on why to do it: - Making it easier to read and understand the code (and a well fitting blog post structure analogy) - thinking about you as a past self/current self and a future self that might come back to the project in the future while perhaps having forgotten a few things about it already. Thanks for the vid!
@artcadedev
@artcadedev Жыл бұрын
By the time I saw the thumbnail you had already earned a sub
@JewGames
@JewGames 3 жыл бұрын
Your videos are great, so much dedication and work on each video you do, amazing please keep it up! :)
@InfallibleCode
@InfallibleCode 3 жыл бұрын
Thank you so much!
@Tarodev
@Tarodev 2 жыл бұрын
I'm working on a conventions video (might be a little more passive aggressive than this video...) and I loved your concept of there always being at least two people working on the project. Do you mind if I quote you with attribution on my video?
@shieldgenerator7
@shieldgenerator7 4 жыл бұрын
In Visual Studio, use CTRL+K, CTRL+D to autoformat the current file.
@Matthew-zs8nm
@Matthew-zs8nm 2 жыл бұрын
Bro, you're hilarious. This was also a great video for a beginner like myself. Subscribed.
@DeathxStrike18
@DeathxStrike18 2 жыл бұрын
I tend to do Public Field > HideInInspector Public Field, Serialized Private Field, Private Field. My logic is the more exposed variables are at the opening of the Script with more secure variables deep within the script. Open > Closed formatting. Think of the script as a box the deeper you dig into the box the harder to get to the items.
@Gaisiran
@Gaisiran 3 ай бұрын
A pleasure to watch!
@Spherous
@Spherous 4 жыл бұрын
Another great video! Keep it up! I really like your format, by the way, flows well.
@sebastianbryant4216
@sebastianbryant4216 2 жыл бұрын
Great video as always!
@InfallibleCode
@InfallibleCode 2 жыл бұрын
Thank you :)
@hansshadow360
@hansshadow360 4 жыл бұрын
conventions begin at 3:20
@cuttlas2955
@cuttlas2955 4 жыл бұрын
I love this channel and how simple it is to underestand thing here ,
@subliminalcastillo2126
@subliminalcastillo2126 4 жыл бұрын
"Wait. There's 3 of us now?" HAHAHA. That made me laugh so hard that i have a cramp in my chest now.
@PandemoniumGameDev
@PandemoniumGameDev 4 жыл бұрын
Awesome video as always! 🔥 Would love to get a tutorial on the most common mistakes that kill your game's performance and how they can be avoided.
@sparrowhawk81
@sparrowhawk81 4 жыл бұрын
What are your thoughts on how to handle modifying an asset you got off the Unity Asset Store? I haven't really come across the need to do this yet personally, but I know you are allowed to modify the source code of assets (the ones that aren't DLLs I mean) you get off the asset store for your own purposes, but I could see myself maybe wanting to rework something someday to add features to it or whatever. Obviously you could just dive in and go for it but have you come across this yourself? Any tricks with inheritance or anything that are useful? Wrapper classes?
@tylocook
@tylocook 4 жыл бұрын
I came here to make a comment that you should not edit the source code of a big asset you import into your project just to style its code to look like yours. The example he used was a snippet of code from Stack Overflow which should not be confused with using somebody's hundreds of lines of code. Maybe Charles disagrees, but I can see why you're confused.
@StefanLopuszanski
@StefanLopuszanski 4 жыл бұрын
I modify them when needed, but try to avoid it because if something updates and fixes some bug I have to go through it manually.
@veeaxis3892
@veeaxis3892 4 жыл бұрын
Is there any naming convention for delegates and events?
@lvx969
@lvx969 4 жыл бұрын
Hold Control and press the E Key and then the D key to auto format spacing and tabbing in Visual Studio Community 2019.
@saito853
@saito853 4 жыл бұрын
Working with a friend on a project for my thesis, his naming convention SUCKS DICK and I'm sending this to him. Thanks for the great video Charles (and Barles)
@RobLang
@RobLang 4 жыл бұрын
Complaining about m_ while still doing _. IDEs can colour variables by scope so you don't have to do that. Otherwise, love the video, great job.
@lucasmontec
@lucasmontec 4 жыл бұрын
You can choose a convention with your team for your project that is close enough to the c# one but still more up-to-date. Your code base just have to be consistent with itself and across time.
@RobLang
@RobLang 4 жыл бұрын
@@lucasmontec I completely agree that it's the choice of every team. In my team, it's my choice! 😀 The underscore is a hangover of Hungarian notation, which was phased out when IDEs became more interactive. 👍
@lucasmontec
@lucasmontec 4 жыл бұрын
@@RobLang I have banned the use of underscore im every team I have worked with. We are in 2020, there is absolutely no reason to use it, just makes code ugly and hard to read.
@RobLang
@RobLang 4 жыл бұрын
@@lucasmontec lol! Perhaps we should start a revolution?
@tylocook
@tylocook 4 жыл бұрын
I like to use m_ or _ just so I can type those first characters and have intellisense show me all the member variables. I use it to categorize class level variables
@stefano4993
@stefano4993 3 жыл бұрын
Great video! Totally agree about consistent naming. Just not sure about private and public methods. I try to keep them logically structured, also because of regions....
@risulkarim5781
@risulkarim5781 4 жыл бұрын
Hey Charles, great stuff once again.. you guys are being my favorite couple of mentors :-D Just curious about which font you use? It looks so cool
@verified_tinker1818
@verified_tinker1818 4 жыл бұрын
3:31 I'm going to murder anyone who does this to my code. Nothing triggers me more than braces going below the declaration. It's ugly, inelegant, and almost never makes the code any more readable. On a brighter note, what's that font you're using? It looks rad!
@nooftube2541
@nooftube2541 4 жыл бұрын
Looks like you aren't from c# world :)
@neitron29
@neitron29 4 жыл бұрын
Personally, I hate Upper case for public members, because Unity`s libraries are written with lower case rule. Why Would you prefer to mess up with both?
@jorhoto7064
@jorhoto7064 4 жыл бұрын
could be a way to distinguish between yours and Unity ones.
@nooftube2541
@nooftube2541 4 жыл бұрын
But you still using system lib, so it would be messed up anyway. Dat unity developers.....
@albertoravasio849
@albertoravasio849 4 жыл бұрын
Which visual studio do u use? It's different form the default one
@yuan3234
@yuan3234 4 жыл бұрын
Its Rider IDE
@travelsizedlions
@travelsizedlions 4 жыл бұрын
You mean the bracket thing isn't the most polarizing?
@Redheadtama1
@Redheadtama1 4 жыл бұрын
Hi Charles. Thanks again for continuing to teach best practices! You always give accurate and helpful info. If you don't mind, could I offer a little bit of constructive feedback? Please don't take it the wrong way. I honestly just want to help but feel free to ignore me if you disagree with my comments :). OK here goes: Personally I find the structure of these videos can distract a bit from the information you're providing. It can come across a little bit cringe and feels like it takes twice as long to put your point across. I say this because sometimes I find myself re-watching one of your videos to remind myself of something you said, but it's really difficult to find what I need because I have to filter through all this exposition and conversation between you and yourself. Again, thanks for your work on these videos. I honestly do appreciate it. Also I purchased Enhanced Hierarchy recently and it's been great so I will be sure to leave you a positive review on the asset store :).
@RayHorn5128088056
@RayHorn5128088056 2 жыл бұрын
Why can't I use whatever code I want to write so long as it works?!?
@UsatiyNyan
@UsatiyNyan 4 жыл бұрын
As a C++ dev I feel personally attacked by first brace not being on the same line as a class/function declaration
@nooftube2541
@nooftube2541 4 жыл бұрын
Dat c++ guys come to c# place their braces on same lines and leave... and c# guys have to leave with it...
@TheLucausi
@TheLucausi 4 жыл бұрын
Where is the Civil War? Camel vs Pascal? just kidding. Your video is awesome, great coding conventions! ( Don't agree too much with underscore on attributes fields, but i love u anyway xD )
@Abken.
@Abken. 4 жыл бұрын
Really good video. 👍 I always fight already lost matches with people on Reddit who hate conventions and they always dislike me when I say that public fields are bad. Everyone starts crying how they are not bad if they're used well. What's the problem with writing good code from the beginning. If I mention SOLID I instantly get 20 dislikes :D But reddit guys hate even properties.
@agnichatian
@agnichatian 4 жыл бұрын
Yeah, many people hate discipline.
@nooftube2541
@nooftube2541 4 жыл бұрын
Public fields doesn't related with SOLID anyhow. Actually no matter you use public field or property with public setter even from the point of encapsulation view, because both provides same API. The only problem with field that it is not obvious that it should or should not be changed from the outside, but a blind changing it to property won't make your class encapsulated.
@Abken.
@Abken. 4 жыл бұрын
@@nooftube2541 This is true, but a wrong mentality. I'm so tired of this topic. My idea is that when you are creating a new class, you should make anything { get; private set; } if you don't need validation or another logic at this point. Then you realize that you need to expose a setter. There is no difference if you make the exposure through a method or through the setter, it's still an exposure. But at least you will think about "why do I need to expose this property, are there no other solutions to this problem, etc". This is way better than making everything public field and then going back to encapsulate only what you need, because you will ignore/skip unintentionally many cases where you can avoid data exposure. If you are a newbie C# dev, it will be much easier to just write every field as a property with private set and it will be much easier to understand why do you need to hide the unneeded data. That's why in universities the OOP topic is so important that the exams are literally "what's encapsulation, what's polymorphism, what's inheritance" instead of writing some code and solving real problems. It's important that the new devs will know why these things matter. Also I've never mentioned that public fields have anything related with SOLID, but if newcomers don't understand what's encapsulation and why it is important, how can we expect that they will follow SOLID on their desk job as web dev, game dev, etc.? And believe me, if you go to Ubisoft's Unity interview (they need Unity devs right now for a 3D game), they will ask you about OOP, SOLID and not ECS. If you look for ECS jobs - yes, they don't ask for such skills, because they have use almost no inheritance at all. ECS vs OOP is another topic. But yeah, it's easier to start from {get; private set;} and learn why it is needed. The most important thing that OOP teaches is discipline - it makes you write good readable code because not everyone works on its own project alone.
@nooftube2541
@nooftube2541 4 жыл бұрын
@@Abken. though I suggest never write public get property at first. Use readonly private fields, and only when you realize it is needed to be exposed, convert it to public property.
@Abken.
@Abken. 4 жыл бұрын
@@nooftube2541 Yeah, yeah. I meant that if I need to expose data my workflow is - create a property without set, then add private set, etc. Of course that the other data that we don't need exposed should be private fields. And readonly is a good advice that many people that come from Typescript or C++ to C# do, but most of the C# devs don't do. But it's a good advice anyways.
@jorhoto7064
@jorhoto7064 4 жыл бұрын
According to conventions should we use the prefix: _ for all our private fields? Option 1 or 2? E.g.: 1. private health 2. private _health
@EricKesterson
@EricKesterson 4 жыл бұрын
personally, I always declare as private int health; and then when referencing I use this.health. My argument for using "this.health" is that it is the ONLY coding style that is also a language feature which CANNOT be interpreted another way. I've seen "_" used in many different ways, so if you jump between projects or copy some code you could easily become confused by its use.
@nooftube2541
@nooftube2541 4 жыл бұрын
As you prefer.
@halivudestevez2
@halivudestevez2 2 жыл бұрын
I hated underscore for a long time ( used "this"). Now I started using it. Seems professional, and one more difference against the local variables in the method. _ health - class member private field health - local variable .... this._health - overwhelmed signature
@ujjwalgupta1204
@ujjwalgupta1204 4 жыл бұрын
Nice Video
@imxron
@imxron 4 жыл бұрын
The amount of time I've spent convincing teams I've worked on to use auto formatters / linters is almost as long as coming up with variable names. Ctrl + Alt + L 😉.
@benoitrousseau4137
@benoitrousseau4137 4 жыл бұрын
Amusingly, Unity is at odds at a few places with the official C# style guidelines from Microsoft. For example, public fields should be pascal cased in C#. (ie Time.DeltaTime, not Time.deltaTime.) That said, I would use the Unity style when working in Unity.
@ujjwalgupta1204
@ujjwalgupta1204 4 жыл бұрын
new to the channel
@StefanLopuszanski
@StefanLopuszanski 4 жыл бұрын
No mention of where to put the { }? :-P
@Konomira
@Konomira 4 жыл бұрын
3:42
@jorhoto7064
@jorhoto7064 4 жыл бұрын
Hi, did anyone notice the 2 guys in the video are very similar?
@victrolaface
@victrolaface 4 жыл бұрын
Charles in charge, of my life, of my youtube.
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 4 жыл бұрын
CLASSIC
@Patrick_Bard
@Patrick_Bard 2 жыл бұрын
Coming from a cooperate Java background, curly brackets on their own line is the only rule I can't stand.
@ImranDaybyDay
@ImranDaybyDay 4 жыл бұрын
Charles is like Clark Kent
@Bossti
@Bossti 4 жыл бұрын
Opening brackets on its own line make me sick ^^"
@Unavailable8923
@Unavailable8923 3 жыл бұрын
Same here. It just pushes code off the screen by wasting vertical space.
@jorhoto7064
@jorhoto7064 4 жыл бұрын
What if I have a class Health and a property Health? Should we name it the same? public class Health { public int Health {get; set;} }
@divingradish
@divingradish 4 жыл бұрын
I would do this: public class Health { public int Value {get; set;} }
@nooftube2541
@nooftube2541 4 жыл бұрын
You can't do it. It won't compile.
@FuzzyDPozzy
@FuzzyDPozzy 4 жыл бұрын
use underscore for private fields such as private float_number;
@Faygris
@Faygris 4 жыл бұрын
I only use Hungarian pascal snake case. *private string M_Str_Prove_Me_Wrong;*
@InfallibleCode
@InfallibleCode 4 жыл бұрын
Lmao 😂
@razveck
@razveck 4 жыл бұрын
Ugh
@daniilparokonnyy7980
@daniilparokonnyy7980 4 жыл бұрын
Should you use "_" or not - that is the question!
@alonsorobots
@alonsorobots 4 жыл бұрын
you just snuck in the underscore before the variable without mentioning it!
@DoubleM55
@DoubleM55 4 жыл бұрын
I find it ugly having private fields start with underscore. Any IDE will not let you use private fields outside class, so I don't even see the point. If it was really important then compiler should check it, but it's redundant and pointless.
@doge9203
@doge9203 3 жыл бұрын
ah not the brackets
@InfallibleCode
@InfallibleCode 3 жыл бұрын
Darn those pesky things...
@ApacheGamingUK
@ApacheGamingUK 3 жыл бұрын
Why does Unity force people to break the C# Coding Standards? Intellisense is a total mess, and makes it so easy to break encapsulation.
@tomerssh
@tomerssh 4 жыл бұрын
6:37 my engineering career in a nutshell
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 4 жыл бұрын
after speeding up ur vids to 1.25, i know that u slow them down before uploading them to youtube.
@АскольдМакарук
@АскольдМакарук 4 жыл бұрын
I hate fucking skype tutor format so much but your videos are too damn informative
@andredias5061
@andredias5061 3 жыл бұрын
my brains hurts... who am I? is there a life worth living? what's life? Is Life alive by itself?
@YuvrajRaghuvanshiS
@YuvrajRaghuvanshiS 4 жыл бұрын
Curly braces on next line.... Noooooo
@ionthruster9572
@ionthruster9572 4 жыл бұрын
recommend vs+Reshaper
@nooftube2541
@nooftube2541 4 жыл бұрын
Rider - x64, vs - x86 (and will never be x64). Checkmate.
@enriquellerena4779
@enriquellerena4779 2 жыл бұрын
m_ I remember that, what a pain. Xd
@unlockener
@unlockener 4 жыл бұрын
Unity properties vs c# properties. Why bring more chaos to this world
@googleuser4720
@googleuser4720 4 жыл бұрын
Ha ameteur!
Namespaces in Unity
7:05
Infallible Code
Рет қаралды 63 М.
Dependencies in Unity
8:24
Infallible Code
Рет қаралды 32 М.
Caleb Pressley Shows TSA How It’s Done
0:28
Barstool Sports
Рет қаралды 60 МЛН
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН
Humble Objects in Unity
9:46
Infallible Code
Рет қаралды 31 М.
Here's How You Should Be Thinking About Data
10:56
Infallible Code
Рет қаралды 36 М.
A BETTER way to setup new unity projects!
15:44
Jason Storey
Рет қаралды 57 М.
4 Tips for Refactoring Your Code for Readability
14:58
Infallible Code
Рет қаралды 31 М.
How Thinking in Systems Can Improve Your Code
10:16
Infallible Code
Рет қаралды 32 М.
5 C# Naming Conventions I Wish Everyone Followed
12:46
Amichai Mantinband
Рет қаралды 18 М.
Code Smells - 'Switches' in Unity3d / C# Architecture
25:21
Jason Weimann (GameDev)
Рет қаралды 78 М.
10 Unity Tips You (Probably) Didn't Know About
8:58
Sasquatch B Studios
Рет қаралды 13 М.
Unity Job System - A Practical Code Example
13:50
Infallible Code
Рет қаралды 83 М.
Software Architecture in Unity
7:13
Jason Storey
Рет қаралды 123 М.
Caleb Pressley Shows TSA How It’s Done
0:28
Barstool Sports
Рет қаралды 60 МЛН