Тёмный

C# Beginner Tips 

Tarodev
Подписаться 96 тыс.
Просмотров 28 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 122   
@vertxxyz
@vertxxyz 2 года назад
I feel like you cannot mention null coalescing operators without mentioning they they do not work properly with UnityEngine.Object types. Which is a major part of Unity development. The equality operators (== and !=) for UnityEngine.Object types have been overridden by Unity, and don't only perform reference comparisons, this makes it possible to Destroy an Object somewhere, and have an entirely different reference evaluate to null. What this also means is that these objects are not actually null, and attempting to use them will cause exceptions and various other issues. The null conditional (?.) null coalescing (??, ??=) operators, and is null checks (is null, is not null, is {}) will not function correctly, as Unity cannot override those operators.
@Tarodev
@Tarodev 2 года назад
You're right. I'll pin this as a disclaimer
@zakkaioken2812
@zakkaioken2812 2 года назад
that just happens to be a case where you shouldn't be using a unity object at all. if you need that actual c# null just use a basic c# class instead of derriving unityengine.object.
@Konitama
@Konitama 2 года назад
Wish I read this before I went through like 20 scripts and changed all my if == null to ??= thinking I was making my code a bit neater... only to get nonstop game object not found errors.
@_IronLion_
@_IronLion_ 2 года назад
@@Konitama 🤣
@petrusion2827
@petrusion2827 2 года назад
This is exactly why I absolutely hate writing "== null" in Unity. It just expresses intent so horribly, you write null checking code but in reality you just want to know if the object had been destroyed. Instead I either use the fact that UnityEngine.Object types have implicit conversion to bool (by writing if(object) ...) or make and use an extension method (like if(object.IsDestroyed()) ... ) And I use the "is null" / "is not null" syntax when I actually want to check for null reference. That way I don't have to think twice about the intent of the code I'm reading.
@zeido86
@zeido86 2 года назад
Since Brackeys shut down, you are my favorite source of Unity tips. Thank you.
@AnnaGlin
@AnnaGlin Год назад
this! although he's at a higher level than Brackeys and assumes the audience knows a lot more coding terms and concepts, I wish he'd go a liiittle bit slower sometimes.
@DanPos
@DanPos 2 года назад
The null-coalescing operator is great, didn't know about that one!
@capsey_
@capsey_ 2 года назад
Use those with caution in Unity, since Unity types may not work with these
@Vastlee
@Vastlee 2 года назад
Great tips. The only issue I have is with putting behavior in the Property. The problem is that when a setter is called that's all you expect to happen. When unexpected behavior happens, especially if something breaks, chasing down the problem becomes difficult.
@Tarodev
@Tarodev 2 года назад
Yeah it certainly couples it strongly. A better approach is the event trigger my overlay mentioned
@dominikjung9294
@dominikjung9294 2 года назад
Yeah that tip I also strongly disagree with. Never ever would I recommend putting special behaviour in getters or setters. Getters and setters should only do that - get and set. If you want some kind of extra validation, add an extra method which handles the validation, and then sets the member via the basic setter. Because sometimes you want to set a value which is not valid - for debugging purposes for example or for tests, or other reasons. And a basic setter is the last place where you look at, when you want to find out why your member doesn't have the value you assigned to it., because you expect it to do its job and nothing else.
@JeremiahT
@JeremiahT 2 года назад
4:12 I've often used this example for checking plurality. string result = amount > 1 ? "people" : "person";
@andersencastaneda6080
@andersencastaneda6080 2 года назад
Nice video. The null coalescing operator is part of C# 8, so only will be available on Unity 2020 or newer.
@Tarodev
@Tarodev 2 года назад
Good thing to note
@broganking9830
@broganking9830 2 года назад
Oh that IDisposible tip was good. I didn't think of that one will add that to my stopwatch wrapper too 🙌
@aliengarden
@aliengarden 2 года назад
I'm really glad I discovered this channel, Currently bringing through all videos. These are the types of video I needed!
@lukastomasek8038
@lukastomasek8038 2 года назад
I’m glad I found this channel, keep up the good work 👍
@mofodumbas
@mofodumbas 2 года назад
Wow, string builder tip is very useful. I forgot about performance issues which concatenating string may cause ☝️
@CCV334
@CCV334 2 года назад
Great tips! Would love to learn about the events approach. Maybe a RU-vid short on it?
@romansalnikov5079
@romansalnikov5079 2 года назад
I have been developing on Unity and C# for a year now, but most of these tips were new and useful to me. So bases on the title of this video I'm still a beginner...DDD
@onidres
@onidres 2 года назад
Great tips, thanks! Oh, the title. You got me :D
@larryd9577
@larryd9577 2 года назад
Eitherway using a StringBuilder or not, you are creating 10k Strings. What you gain by using a StringBuilder is not building intermediate Strings, which get "previous Strings + current String" assigned to it and thrown away after the next concatenation. I didn't benched it but i would use the build step AppendFormat for appending something formatted instead interpolating it and then append it. Or append both parts of the string "A string: " and the int separately. But that could be a micro optimization. Great video Matt!
@Tarodev
@Tarodev 2 года назад
You're the first person to take note of my name in a video and call me by it! I've enjoy all the comments you leave on my videos by the way. The extra little bits of information I leave out which are equally important. Really appreciate you spreading your knowledge!
@Illu07
@Illu07 2 года назад
Thanks for the appreciation! Keep up with this good stuff.
@vertxxyz
@vertxxyz 2 года назад
We totally won't have access to this for a while in Unity, but in .NET 6 StringBuilder's methods take in interpolated strings and process the formatting logic internally without allocating a string. All of this stands true until we get .NET 6, but it's worth noting when you're programming outside of Unity!
@Tarodev
@Tarodev 2 года назад
@@vertxxyz In my younger dev days I had an application in production with a few companies using it. One of it's functions was to take a bunch of rows from a register (10k+ sometimes) and build a PDF to download/print. The server would sometimes lock up, not just for the person trying to print a PDF, but for all the companies at that time... Turns out concatenating 15 fields separately from each row is not ideal when you have 10k items...
@Tarodev
@Tarodev 2 года назад
@ stringception?
@castlecodersltd
@castlecodersltd 6 месяцев назад
Some great advice. Thank you 🙂
@gatorgothgrrl
@gatorgothgrrl 2 года назад
the editing kept my attention on the video, thanks for the silliness
@Tarodev
@Tarodev 2 года назад
Too many professional tutorials out there, I think...
@NaruHinn
@NaruHinn 2 года назад
Thank you so much for the awesome tips, great vid as always.
@JoschinoDev
@JoschinoDev 2 года назад
Wait this is beginner info? What did i learn in my 3 years of CS school? But like always great video
@smokinglife8980
@smokinglife8980 2 года назад
Yeah all this is pretty basic
@Warwipf
@Warwipf 2 года назад
You probably learned multivariable analysis, numerics, algorithmics, complexity theory, logic, etc? My CS degree was not focused on programming AT ALL. We had like 4 modules where we even used a computer, lmao.
@smokinglife8980
@smokinglife8980 2 года назад
@@Warwipf yeah and that's why we say you don't need a degree to do shit just gotta put your mind to it
@Warwipf
@Warwipf 2 года назад
@@smokinglife8980 While this statement is true, a degree will still help. This might not be true for your country, but since uni is free here it's way harder to get a job in the field if you don't have a degree. Everyone who is capable of getting a CS degree and wants to go into the field usually just gets one, so if you don't have one you'll not exactly be first choice. If you're not capable of that and just have an apprenticeship (or nothing at all) you'll usually earn a lot less for the same job and your career options are severely limited unless you're just super good at your job. I find it weird, because CS is not inherently about programming and many unis don't focus on programming very much. My CS degree comes in handy only when dealing with very complex stuff or difficult maths, which is not very often.
@Warwipf
@Warwipf 2 года назад
I got that degree only so I have something to fall back on if my grand ambitions to become a full-time gamedev fail. :D But I gotta say, it was a lot of fun and I found somewhat of a passion in the field, but maybe that's just Stockholm Syndrome, lol.
@bigedwerd
@bigedwerd Год назад
So many good tips! Especially with the string builder. That could make a huge difference with a text heavy game. I suppose you can also use null coalescing for lazy loading. Say for example your code requires a rigidbody. rb ??= gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody; though I'm sure it's better to have the user put it themselves with desired values Edit: oops, shoulda read the pinned comment. Probably good for other lazy loading though.
@queenofpain6483
@queenofpain6483 2 года назад
I personally don't (or rarely) use the else statement for anything. It makes my code easier to understand (for me) and much cleaner with less brackets. I also don't use the switch statement at all. Instead, I just do a bunch of "if() return;"s. I don't know if there's any performance impact on my choices but like you mentioned it's just my personal preference. :) Love your videos
@DJnoratos
@DJnoratos 2 года назад
As a professional programmer I can tell you that even in most companies they recommend you to not use else branch if possible.
@petrusion2827
@petrusion2827 2 года назад
You should really consider using switch though, especially if you are using multiple "if() return;"s. In games performance is important and switch has better performance than multiple ifs. The compiler doesn't just generate a bunch of ifs when lowering switch, it often uses binary search or hashing.
@trashcaster
@trashcaster 2 года назад
The "set override" was neat to me. I come from a predominantly Java background, so learning new C# things is nice for me, and gives me more reasons to like it over Java. Being able to effectively bind a value to a string is super handy. No more calling update/refresh functions.
@LeoninMinecraft
@LeoninMinecraft 2 года назад
is there a video that explains the use of the "using" keyword? I didnt know it had uses outside of calling for namespaces/statics at the top of you script. I tried reading the docs page for it but i didnt really understand it.
@Tarodev
@Tarodev 2 года назад
It's a special keyword specifically for the Idisposable interface. It allows you to encase some logic which uses the disposible class, giving you granular control for when to call dispose.
@neozoid7009
@neozoid7009 2 года назад
Awesome tips Thanks. By the way why Do you use VS Code instead of VS ?
@Tarodev
@Tarodev 2 года назад
I user rider nowadays 😊
@ryanarata361
@ryanarata361 2 года назад
Great title and tips 😅
@youcancallmedoggie
@youcancallmedoggie 2 года назад
Pieces of strings!! Great vid, great title!
@_Garm_
@_Garm_ 2 года назад
thank you! learned alot :D
@supendi42
@supendi42 2 года назад
Why does this guy only have 9k subscribers 😭
@rafaelgpontes
@rafaelgpontes 2 года назад
Hey, quick question: what is the size of a "Hello World" app made with Unity? Does C# introduce a big core bundle overhead to the exported binary?
@Tarodev
@Tarodev 2 года назад
Unity builds can be as little as 15mb (2mb using a special sub-version called project tiny).
@rafaelgpontes
@rafaelgpontes 2 года назад
@@Tarodev, interesting!! Thanks for the reply! =)
@fejza
@fejza 2 года назад
Never saw someone name namespaces using an underscore prefix. It hurts my eyeballs. Just kidding, great video!
@Tarodev
@Tarodev 2 года назад
Do you mean the variables? It's actually proper c# convention. Only unity decided to discard any decent naming conventions and just wing it. Can you look at a variable in a function and know if its a local or private global, or do you use the same naming convention for both of those things? 😉
@fejza
@fejza 2 года назад
@@Tarodev I was referring to the namespaces, namespace _Scripts { ... } in your examples. I know a lot of people use _ for private fields. I was using it for a long time as well but at some point stopped and I am still alive :D. I feel like the IDE gives me enough context to distinguish. Obviously this is all a matter of personal preference.
@Tarodev
@Tarodev 2 года назад
@@fejza Ahhhhh! Yes, that's just a byproduct of prefixing the scripts folder in the unity engine with an underscore. Certainly a gross one at that. I'd never purposefully do it >
@neevir3229
@neevir3229 2 года назад
great video
@abraiyan7984
@abraiyan7984 2 года назад
Can we get a long video on Events and Delegates, please?
@Tarodev
@Tarodev 2 года назад
I'd say one of the next 3 videos will be this topic :)
@abraiyan7984
@abraiyan7984 2 года назад
@@Tarodev Thanks a lot dude. I really wanna see your channel grow.
@addie7395
@addie7395 2 года назад
Good tips for beginners but you said IDisposable is for cleaning up managed resources but its for unmanaged resources.
@Tarodev
@Tarodev 2 года назад
Woops 😜
@griff424
@griff424 Год назад
i think i need superbeginner tips
@SpicyMelonYT
@SpicyMelonYT 2 года назад
What’s the difference between using ?? and ||. I usually do something like this: var something = somethingElse || somethingMoreElse; which sets something to somethingMoreElse if somethingElse is null. Edit Turns out I was thinking of javascript. Lol
@nerdin8or
@nerdin8or 2 года назад
I think you're thinking of JavaScript, because the || way works there, but not in C#
@SpicyMelonYT
@SpicyMelonYT 2 года назад
​@@nerdin8or Oh I totally am thinking of javascript wow. I started writing all these things about how I am not mistaken but then when I went to check what does happen in your scenario it was confused. Lol yeah I guess thats what happens when your code in both languages every day and also comment on a youtube video in the middle of the night half asleep
@nerdin8or
@nerdin8or 2 года назад
@@SpicyMelonYT I've been there! And I only guessed that because I do most of my work in JS :D
@SpicyMelonYT
@SpicyMelonYT 2 года назад
@@nerdin8or Haha yeah. I start a new project just about every 3 days and so I test out the concept on javascript first cause its way easier to get a previs for it on there with the P5 Editor. So I feel ya
@buonase1366
@buonase1366 8 месяцев назад
Me watching in order to find if I'm still a beginner ;D
@Tarodev
@Tarodev 8 месяцев назад
And how'd that go?
@buonase1366
@buonase1366 8 месяцев назад
​@@Tarodevsome strict c# tricks were new to me and I am happy to discover them, thank you 🤝🏻
@benthroop2461
@benthroop2461 2 года назад
Whatever possessed you to flash PIECES OF STRING is a proper impulse and must be protected
@Tarodev
@Tarodev 2 года назад
Something deep down told me to do it
@9000writer
@9000writer 2 года назад
thank god not syntax but tools to get shit done.
@MrLazyfella
@MrLazyfella 2 года назад
Nice beginner tips! The title is kinda cringe.
@Tarodev
@Tarodev 2 года назад
In a good way
@Letsamplay
@Letsamplay 2 года назад
Dude, that title really sucks. Come on you're better than that!
@Tarodev
@Tarodev 2 года назад
I make a lot of my titles inappropriate. This one is a little much though :P I may tone it down a bit
@Letsamplay
@Letsamplay 2 года назад
@@Tarodev I don’t mean to come across as overly sensitive. More that your channel is great and doesn’t need teenage boy humour. But idk what the algorithm likes I guess haha so…
@fulongfromthegrave
@fulongfromthegrave 2 года назад
I like the titles...
@Tarodev
@Tarodev 2 года назад
@@Letsamplay I don't mean to offend and I'm sorry if I did. I may be guilty of having teenage boy humor to be honest 😂 Hopefully more people like them than not >
@neoclypticalconundrum1201
@neoclypticalconundrum1201 2 года назад
@@Tarodev You shouldn't care about anyone being offended. At the end of the day that is their problem and not yours. If anything, seeing these "offensive and dirty" titles just reminds me that the video is made by you, which I then instantly associate by quality and want to watch it. Be yourself, and thank you for the amazing content!
@homemacai
@homemacai 2 года назад
Nice! This tips are amazing, wouldn't mind a few more , maybe with scriptable objects or tasks/coroutines. Cheers
@WingofTech
@WingofTech 2 года назад
Coroutines for sure, always a powerful tool to learn.
@DemsW
@DemsW 2 года назад
Great tips, I knew most of them but things like string builder and the print are good to know . This would have been so valuable to have when I was starting out so good job
@Warwipf
@Warwipf 2 года назад
print is going to change my life
@ZakBazzinga
@ZakBazzinga 2 года назад
bruh i clicked on this vid just becuz of the title lol 🤣😂🤣
@Tarodev
@Tarodev 2 года назад
And was it worth it?
@StabilerLoeffel
@StabilerLoeffel 2 года назад
👍🏻
@eadlef
@eadlef 2 года назад
instance ??= this; The gourmet singleton
@Tarodev
@Tarodev 2 года назад
That is beautiful
@fokeyjo
@fokeyjo Год назад
The number of unity tutorial vids where I see people doing: if (condition) { return true;} else { return false;} across up to 8 lines is obscene! And I've used the inverted if approach for many years now, massively improves legibility. Also mimicks preconditions, a principle in CompSci proof stuff (it's been many years since I did my CompSci degree!). However, if you can possibly avoid them, do, because it is adding branching logic which is computationally expensive - i.e. only do this for really important conditions. It's why substates can be important to avoid typical state checking logic.
@m_maksym
@m_maksym 2 года назад
great tips! thanks a lot! as a beginner i can say it's cool i found your channel! (youtube recommended to be honest)
@ThomasWapps
@ThomasWapps 2 года назад
The tip for the Stringbuilder is very nice! Thanks
@NoTimeLeft_
@NoTimeLeft_ 2 года назад
Me before vid: Beginner! Me After vid: "Beginner"
@Tarodev
@Tarodev 2 года назад
Heh 😊
@franklin6697
@franklin6697 2 года назад
Thanks.. Animation mask tutoriel please
@AmNothi
@AmNothi 2 года назад
Nice one, solid tip
@in2fractalout
@in2fractalout 2 года назад
supernice. need it to look ones
@djblast101
@djblast101 2 года назад
The title is why I clicked 😂
@noobcraft5712
@noobcraft5712 2 года назад
Am I a noob🤔
@Tarodev
@Tarodev 2 года назад
You sure are ;)
@krobro1627
@krobro1627 Год назад
Can you do a beginners tutorial to making a tower defense? You really seem to know what youre doing and a tutorial would be so good
@notagamedev5494
@notagamedev5494 2 года назад
You are jesus of Unity Tutorials
@istegal8079
@istegal8079 2 года назад
Nice Video, learned some new stuff. Any eta on the optimized a* video? Can’t wait to finally implement it into my project
@Tarodev
@Tarodev 2 года назад
At some stage! Probably after a dots video as it makes use of it
@SpicyMelonYT
@SpicyMelonYT 2 года назад
That title!!! Hahaha nice. And good video. Maybe post videos during 2-3 pm for pst cause that’s when the most eyeballs are active in the world. But I understand you might be posting at prime time for where you live so it’s just a suggestion
@Tarodev
@Tarodev 2 года назад
I'm experimenting with timezones right now. It's nice having an immediate rush when it's first released, but over time it doesn't seem to make much difference.
@SpicyMelonYT
@SpicyMelonYT 2 года назад
@@Tarodev Oh yeah that seems to be the case for a channel as big as yours but for mine, that "rush" determines if my video gets 500+ vies or nothing at all and fades away in existence. But for you the rush can be a valuable time for figuring out if a video thumbnail and title is the best match. This video at 8:02 explains this well and its by Veritasium so you know its good: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-S2xHZPH5Sng.html
@Tarodev
@Tarodev 2 года назад
@@SpicyMelonYT Ahh, I love that video! So true. I should go through some videos and change up the name/desc/thumbnail to see if it sheds some extra views on it.
@SpicyMelonYT
@SpicyMelonYT 2 года назад
@@Tarodev You definitely got me as an invested viewer and subscriber! Love watching you videos cause as someone who is completely self-taught with programming (youtube and forums taught) I love seeing clean code and sleek examples that you make! Hopefully more people share that view in the future!
@SpicyMelonYT
@SpicyMelonYT 2 года назад
@@Tarodev Oh and also its DO tween... HAHAHA
Далее
20 Advanced Coding Tips For Big Unity Projects
22:23
Просмотров 186 тыс.
The weirdest way to loop in C# is also the fastest
12:55
Watermelon magic box! #shorts by Leisi Crazy
00:20
10 Things You NEED to Be Doing in Unity
11:40
Просмотров 132 тыс.
My 2 Year Journey of Learning C, in 9 minutes
8:42
Просмотров 614 тыс.
The Most Legendary Programmers Of All Time
11:49
Просмотров 565 тыс.
The purest coding style, where bugs are near impossible
10:25
Is C# hard to learn?
10:05
Просмотров 131 тыс.
6 Years of Learning Game Development
9:02
Просмотров 2,4 млн
5 (Extreme) Performance Tips in C#
12:26
Просмотров 75 тыс.
Why You Shouldn't Nest Your Code
8:30
Просмотров 2,7 млн
C# Extension Methods
9:46
Просмотров 23 тыс.
Ditch your Favorite Programming Paradigm
6:08
Просмотров 183 тыс.