The .NET 7 feature that gives meaning to your Strings

  Рет қаралды 48,727

Nick Chapsas

Nick Chapsas

Күн бұрын

Пікірлер: 147
@AJax2012
@AJax2012 2 жыл бұрын
Great feature! Also, thank you for saying that "nobody knows regex". One of the senior devs at my first dev job told me that I "had to learn regex" because it was "important to know off the top of your head" and it's good to know I'm not alone 🤣
@Jennalcn
@Jennalcn 2 жыл бұрын
I am no one.
@GarethBradley
@GarethBradley 2 жыл бұрын
I think they were pulling your leg fella. Like when painters start the first day of a job and are sent to buy tartan paint....
@AJax2012
@AJax2012 2 жыл бұрын
@@GarethBradley typically, I’d agree with you. This guy was weird though. I’ve been working in the field for 4 years and I have yet to find anyone else who can just write complex regex without looking it up. He went as far as to buy me and the other new dev a pocket handbook on regex and gave us homework, lol. They did give me a troll assignment on my first day though, so who knows…
@modernkennnern
@modernkennnern 2 жыл бұрын
Regex, while rarely mandatory, are incredibly useful for doing small repetitive tasks. "Ugh, I have to convert all top-level structs and classes in my project from being Public to being Internal.. That'll take forever.". "public (class|record)" -> replace with -> "internal $1". This is not "production-ready," as it misses readonly structs, record structs, readonly record structs and so on, but the idea is there.
@AJax2012
@AJax2012 2 жыл бұрын
@@modernkennnern yup, that’s almost entirely where I actually use regex. Find and replace
@litarea
@litarea 2 жыл бұрын
6:00 holy crap that is unbelievably useful. Most IDEs behavior of just broadly ignoring the contents of strings has always seemed like a missed opportunity to me. Countless times I've had to use separate validators and copy in from there.
@Nezbo
@Nezbo 2 жыл бұрын
I was chanting "Attribute Attribute Attribute" for about 3 minutes until the reveal :D Happy they went this way.
@Zashxq
@Zashxq 2 жыл бұрын
omg this is crazy. this is crazy!!! as a library dev this is an absolute gamechanger for me. wow wow wow
@jongeduard
@jongeduard 2 жыл бұрын
Great video. I didn't know about the older comment way indeed. I just tried and noticed that lang=date, lang=time or lang=datetime also works (trying with VSCode now). 1:03 Oh I know how to write them! 😃 Learning about them is like a gift, in coding, but also in Linux shell and Powershell or wherever you want to search for stuff, they are a great thing.
@Phraxas52
@Phraxas52 2 жыл бұрын
I have never seen a more useful programming channel. Thank you.
@Akumasama
@Akumasama 2 жыл бұрын
Oh wow, that is beautiful. And timely too because my current project uses Regexes a lot. Nice!
@briankesecker
@briankesecker 2 жыл бұрын
1) this feature will save many devs from typos and 2) I get the sense this feature could be toggled, such that string parameters can auto-inherit all the way up the stack, thus relieving devs from having to attribute params. That inline Json syntax checking is on fire for unit testing! Thank you Nick!
@alexclark6777
@alexclark6777 2 жыл бұрын
Me: "Huh, probably just a video about string literals, but it's a Nick Chapsas video so I'll watch it." Me after video: "Mind blown. I learned something new."
@th30519
@th30519 2 жыл бұрын
This is a pretty cool feature, it would be fantastic if it supported other languages like SQL, JavaScript, or HTML. How many times have we had to format strings of other languages? to be able to validate them in the IDE without copy/pasting to their native editors would be great.
@drewkillion2812
@drewkillion2812 2 жыл бұрын
Rider has some support for recognizing SQL strings.
@christianhowell3140
@christianhowell3140 2 жыл бұрын
Oh my god if they add support for SQL and HTML I would literally cry of joy (and demand my company upgrade to Net7)
@vertxxyz
@vertxxyz 2 жыл бұрын
JetBrains' Annotations has had RegexPatternAttribute for aaaages which does this same thing. Glad it's standardised and supporting other syntaxes
@codecoffee4952
@codecoffee4952 2 жыл бұрын
I had to write a parser once, so regex was a large part of my day-to-day for a bit. This would have really come on handy then. Looking forward to using this. Thanks for sharing.
@uncommonbg
@uncommonbg 2 жыл бұрын
Holy smokes, that's a pretty cool feature and I can see it becoming better and better with time. Thanks, Nick!
@jimread2354
@jimread2354 2 жыл бұрын
That's amazing! I had no idea that was even a thing, but now I want to know how to write my own. I've had more than one instance where I wrote a proprietary scripting language and this would be a great feature to be able to add in.
@DerekWelton
@DerekWelton 2 жыл бұрын
I would love to see us have the ability to create our own string syntax(yes I know, you should use an enum then) but there are special cases where this would be handy. Thanks for showing this Nick!
@nickchapsas
@nickchapsas 2 жыл бұрын
It's would be pretty cool. I assume this can be done with a VS Extension or a RIder Plugin
@phizc
@phizc 2 жыл бұрын
The parameter to the attribute is just a string, so I assume you can make an extension and look for a custom syntax tag. I doubt the IDE would crash if the string is unexpected. It would probably be like XmlSyntax now.
@AnsisPlepis
@AnsisPlepis Жыл бұрын
1:03 truer words have never been spoken
@marklord7614
@marklord7614 2 жыл бұрын
Wow, this was really useful. Thanks Nick!
@BananaTie
@BananaTie 2 жыл бұрын
Cool feature, thank you for showing us that! I did not know the comment part "/*lang=regex*/" was a thing! That will be helpful for the project I am working on at the moment (stuck at .NET 3.1)
@CordellLawrence
@CordellLawrence Жыл бұрын
@Nick, interestingly, this doesn't work for Anonymous methods. not sure if the IDE's (I'm using VsCode 1.77.1 Windows) just don't look for them on Anonymous methods (I checked the low-level C# / IL and the compiler does include the attribute on the Anon method. e.g. Func find = (input, [StringSyntax(StringSyntaxAttribute.Regex)]expression) => Regex.Match(input, expression); BTW - Thanks for all the awesome content!
@krccmsitp2884
@krccmsitp2884 2 жыл бұрын
Awesome feature, thanks for showing!
@antonmartyniuk
@antonmartyniuk 2 жыл бұрын
A really cool and handy thing! Thanks for the heads up
@xeoneraldo1254
@xeoneraldo1254 2 жыл бұрын
I love Nick's number examples
@mandoschMUh
@mandoschMUh 2 жыл бұрын
Ooookay .. that's a cool feature, indeed! Thank you for sharing this.
@MRender32
@MRender32 2 жыл бұрын
I’m glad the argument is a string so custom formats can be written. I wanna see XPath syntax highlighting
@_emik
@_emik 2 жыл бұрын
Reminds me of TypeScript's awesome template literal feature. So excited to see this validation added in Rider!
@TheMAZZTer
@TheMAZZTer 2 жыл бұрын
I thought this was going to be about a different feature but I guess that's coming in a later .NET. I am looking forward to being able to have string subtypes like Names, PhoneNumbers, etc that define what the contents of a string are for, which will help keep you from accidentally using the wrong string in the wrong place. This is really cool too and I'm going to have to keep it in mind, though I will probably not be able to use it until .NET 8 LTS.
@SlackwareNVM
@SlackwareNVM 2 жыл бұрын
Looks awesome, especially the Json one. I'd be great if we could define our own suggestions. Not syntax highlighting, but just the available options like for the date time formatter.
@petrusion2827
@petrusion2827 2 жыл бұрын
This would make an amazing feature. Custom string syntax highlighting for arguments would make working with things like format strings 10000000% more convenient. Floats for example don't have format string suggestions like DateTime does and I hate having to always look up all the different ways to format a float somewhere online.
@cattman1970
@cattman1970 2 жыл бұрын
Wow that is super sweet. Thank you!😊
@МихаилПлюснин-з8й
@МихаилПлюснин-з8й 2 жыл бұрын
Thank you! Great feature!
@GregUzelac
@GregUzelac 2 жыл бұрын
Very informative and helpful. Thx.
@Crozz22
@Crozz22 2 жыл бұрын
This is great. But ideally I'd wish for type alias in C# instead. So I could declare something like `type RegexPattern = [StringSyntax(StringSyntaxAttribute.Regex)] string`, and then just use the RegexPattern as the parameter without having to specify the attributes on every method (and also make it clearer because i'm passing around RegexPattern and not a plain string)
@TheKub1s
@TheKub1s 2 жыл бұрын
You can write something like this with 'using' keyword: using NullableInt = System.Nullable; I don't know if it works with attributes.
@metaltyphoon
@metaltyphoon 2 жыл бұрын
Seriously, the attribute being long is getting out of hand.
@lordmetzgermeister
@lordmetzgermeister 2 жыл бұрын
in C# there's nothing even remotely similar to what you suggest so that would be hard to do
@ДаниилЧернышев-л5й
@ДаниилЧернышев-л5й 2 жыл бұрын
@@allmhuran Well, we can make use of implicit cast operators between string and any of those classes. Not so typesafe, but better than nothing, I guess.
@sebastienvisser8759
@sebastienvisser8759 2 жыл бұрын
Thanks, Nick.
@alfonsosuarez9317
@alfonsosuarez9317 2 жыл бұрын
It will come in handy. Do you know if we could create custom string sintaxes?
@TedOnTheNet
@TedOnTheNet 2 жыл бұрын
Will be interesting to see custom implementations.
@SmoothSkySailin
@SmoothSkySailin 2 жыл бұрын
Thanks for the great video!
@pdebie1982
@pdebie1982 2 жыл бұрын
Is it possible to create custom syntax attributes in which you can create your own list of "options" to fill?
@emmanueladebiyi2109
@emmanueladebiyi2109 2 жыл бұрын
Thanks for putting out all these great content 🙏🏽
@cn-ml
@cn-ml 2 жыл бұрын
Oh, wow, i cannot even count how many times during development i thought this would be practical. The amount of times i preferred to call the regex constructor with a literal string because it just looks better than a string variable
@AaronShumaker
@AaronShumaker Жыл бұрын
This makes me wonder why we don't have a way to annotate strings as more specific subtypes. There's been many occasions I'd love to have string parameters with specificity so compile time would say "Hey you're trying to pass a HtmlString where a UriString is expected." Or be able to create specialized strong extension methods without polluting every other type of string.
@magicsmoke0
@magicsmoke0 2 жыл бұрын
What's the most performant way to convert an integer to a string in a hotpath (millions of loops)? My benchmarks show a simple .ToString() on the int is faster than using some Span alternative, like int.TryFormat(buffer.AsSpan(), out var x), but has some memory allocation where as the TryFormat doesn't.
@Denmaverick39
@Denmaverick39 2 жыл бұрын
Thanks nick.
@ufukata6789
@ufukata6789 2 жыл бұрын
It's very cool. Can we customize this, for example json format fix warning etc.
@co2boi
@co2boi 2 жыл бұрын
Killer. Thanks!
@saniel2748
@saniel2748 2 жыл бұрын
Can this attribute be applied to fields/consts?
@Anequit
@Anequit 2 жыл бұрын
I love this feature
@mabakay
@mabakay 2 жыл бұрын
Cool feature. ReSharper has had it for years ;-)
@gammafelikx
@gammafelikx 2 жыл бұрын
Nice feature but, as far as 'IDE dependant' feature goes, Rider already have an ''Mark as injected language or reference" funcionality that is quite the same thing.
@Palladin007
@Palladin007 2 жыл бұрын
I love it :D I knew about the "lang=regex" feature and I was looking for a long time for a way to do that with attributes. But I don't understand why the constants are in the attribute class. I think it would be better to have "[StringSyntax(StringSyntax.Json)]" and then the StringSyntax class contains the constants.
@jackoberto01
@jackoberto01 2 жыл бұрын
StringSyntax is just an identifier for StringSyntaxAttribute when you use it as an Attribute this is how all Attributes work in C# for example SerializableAttribute can be written as Serializable or FlagsAttribute can be written as Flags. So it already exists in the place you're suggesting but you need to write the whole name of the Attribute in the constructor. If you wanted to you could write it "[StringSyntaxAttribute (StringSyntaxAttribute.Json)]"
@metaltyphoon
@metaltyphoon 2 жыл бұрын
@@jackoberto01 he is saying that what’s in the parentheses is too long
@jackoberto01
@jackoberto01 2 жыл бұрын
@@metaltyphoon Yeah I get that but this is just a quirk of the language. I guess they could allow the identifier to be used in the Constructors of Attributes but that would require changes to the language
@phizc
@phizc 2 жыл бұрын
@@jackoberto01 they could have put the constants on a class named StringSyntaxes. On the other hand, they're just magic strings so you could do it yourself. 🙂
@Dimich1993
@Dimich1993 2 жыл бұрын
This is great!
@yatsuk
@yatsuk 2 жыл бұрын
Is it possible to define own syntax?
@paulpach
@paulpach 2 жыл бұрын
Wow, cool feature. Makes stringly typed data just a little safer to use.
@womz8203
@womz8203 2 жыл бұрын
"No one knows how to write Regex" This is so true 😭
@yzraeu
@yzraeu 2 жыл бұрын
Video gets nice @ 6:14
@carlitoz450
@carlitoz450 2 жыл бұрын
Wow ! thats nice
@ilShaiHulud
@ilShaiHulud 2 жыл бұрын
Hello. Thanks for the cool video! I am waiting for this feature. Do you know is it will be possible to extend StringSyntaxAttribute with user defined languages?
@ryanjean
@ryanjean 2 жыл бұрын
"No one knows how to write Regex" *timidly raises hand*
@TheAzerue
@TheAzerue 2 жыл бұрын
Hi A simple question. Can Net 7 RC be used in production ? and is it drop in replacement for Net 6.
@nickchapsas
@nickchapsas 2 жыл бұрын
I would not run any RC version in production. Wait for the full release. It will mostly be a drop in replacement
@lordmetzgermeister
@lordmetzgermeister 2 жыл бұрын
It's not a question of whether it can be used but rather whether you should use a "release candidate" version in production. The answer is no.
@amrosamy8232
@amrosamy8232 2 жыл бұрын
Hi Nick, Can you make a video about IAsyncEnumerable plz?
@deusexaethera
@deusexaethera 2 жыл бұрын
I keep telling myself I should learn RegEx, but I keep not needing to. Any string manipulation I could do in RegEx, I can do with other programming structures without having to assume the RegEx parser will do it correctly on my behalf. RegEx is really only useful in the very narrow range of scenarios where you need to modify a string AND pass it to another function in the same line of code.
@Faygris
@Faygris 2 жыл бұрын
Are we not going to argue about the way he pronounces regex? No? Alright. Anyway, great feature! I'm looking forward to using it 😊
@nickchapsas
@nickchapsas 2 жыл бұрын
The original plan was to pronounce it both regex and regex but I forgot to switch it up mid-video
@lordmetzgermeister
@lordmetzgermeister 2 жыл бұрын
I was wondering as well. Surprised there's only one comment here... Anyway it's "rejular expressions" now.
@Joe-SoftwareEngineer
@Joe-SoftwareEngineer 2 жыл бұрын
Nice! Very nice!
@PetrVejchoda
@PetrVejchoda 2 жыл бұрын
1:02 deep truth
@slyp05
@slyp05 2 жыл бұрын
That /*lang=Regex*/ thing is crazy haha. Very nice that new version are trying to make those weird hidden features actually use the clean language features. No more weird "call you method Add, Deconstruct or Dispose and it will actually have a unique behaviour despite nothing telling you about it" in the future ? That would be nice !
@PanMaciek
@PanMaciek 2 жыл бұрын
Nice one
@swordblaster2596
@swordblaster2596 2 жыл бұрын
Interesting. Using this properly eliminates an entire class of possible mistakes.
@shayvt
@shayvt 2 жыл бұрын
What is the state of c# 7? When will it be released?
@samuelschwager
@samuelschwager 2 жыл бұрын
C# 7 was released in 2017. I guess you mean .NET 7? November 2022
@klex3905
@klex3905 2 жыл бұрын
"No-one knows how to write regex" I haven't laughed that hard since your goPilot video!
@hostar2
@hostar2 2 жыл бұрын
My question is: will this attribute compile into the binary?
@itssalmanvlogs_
@itssalmanvlogs_ 2 жыл бұрын
🔥
@iammahie
@iammahie 2 жыл бұрын
1:04 absolutely, Lol 😂😆
@metaltyphoon
@metaltyphoon 2 жыл бұрын
Attribute length is getting out of hand, C# need to have type alias
@Sergio_Loureiro
@Sergio_Loureiro 2 жыл бұрын
1:05 Nick Chapsas: No one knows how to write regex Experienced Perl programmer: *HOLD MY BEER.*
@11clocky
@11clocky 2 жыл бұрын
Could they have made those annotations any more verbose? They take up more space than the method signatures themselves.
@Dobrokhvalov
@Dobrokhvalov 2 жыл бұрын
It would be cool to have SQL support
@EduardQualls
@EduardQualls 2 жыл бұрын
Am I the only one who slows Nick down to 0.75 playback speed, just to make sure I don't miss anything in his excitement?
@TimmyBraun
@TimmyBraun 2 жыл бұрын
I always go with 2x lol, but sometimes I rewind and play back a bit slower when there's something interesting I didn't get :)
@MHjort9
@MHjort9 2 жыл бұрын
Thanks for the sub-10 minute video. I feel smarter quicker
@klaxxon__
@klaxxon__ 2 жыл бұрын
Why is this .Net 7 specific? It doesn't involve the language or the runtime at all, doesn't it? It's all in the IDE. It should be possible to shim this with a custom attribute with the same name and namespace (or a nuget package containing sucha ttribute). A lot of the attributes controlling newer features can be shimmed like this.
@lordmetzgermeister
@lordmetzgermeister 2 жыл бұрын
They'd have to make it so that the nuget package can't be used in a .NET 7+ project. Or use a different namespaces but that'd be confusing. So not enabling it is easier and is an incentive for devs to upgrade to the new version. Win-win.
@klaxxon__
@klaxxon__ 2 жыл бұрын
@@lordmetzgermeister They generally do not hold back features just to incentivize upgrading (in many environments, it is not the developers who decide which version of net gets used, there are many other considerations). Also, they have released shims for language features for older frameworks before (see the package System.ValueTuple , and there were multiple other cases as well, where a new language feature could be easily shimmed onto an older runtime by defining a class/struct or an attribute). The colission thing can be easily sorted out with for example #if NET6_0.
@phizc
@phizc 2 жыл бұрын
Cool! You can also put the attribute on fields and properties (and maybe variables?). I knew about the attribute, but only that it supported Regex syntax. I didn't know they also support json, and seem to plan to support XML.
@dariuszkopec
@dariuszkopec 2 жыл бұрын
61 years old and just purchased tNice tutorials software. i love making my own soft
@kipchickensout
@kipchickensout Жыл бұрын
It's not that complicated to learn basic regex and it not only helped me read it a few times but also write as well as search specific strings in my code to narrow down things
@isen1
@isen1 2 жыл бұрын
whats up with that double """"?
@nickchapsas
@nickchapsas 2 жыл бұрын
It's a new C# 11 feature called, raw string literals.
@th30519
@th30519 2 жыл бұрын
@@nickchapsas I saw a cool video about that feature here kzbin.info/www/bejne/any7iHSdj6prrqs
@Corvin_
@Corvin_ 2 жыл бұрын
Praying dotnet will have a good Uri parser one day.
@tacklemcclean
@tacklemcclean 2 жыл бұрын
This is crazy!! You look so much younger than 69!
@nickchapsas
@nickchapsas 2 жыл бұрын
I use sun screen
@liam7073
@liam7073 2 жыл бұрын
I had no idea the IDE changed behaviour based on comments.
@cedricv-p9z
@cedricv-p9z 2 жыл бұрын
1:03 lol
@frossen123
@frossen123 2 жыл бұрын
Regex is not even a challenge anymore, where were all these tools 20 years ago 😭all the ide features, online "explanation tools" and builders.. oh well, making all our lives easier 😄
@petrucervac8767
@petrucervac8767 2 жыл бұрын
You look pretty young for a 69 years old
@AvenDonn
@AvenDonn 2 жыл бұрын
When you opened VS... Mood.
@masonwheeler6536
@masonwheeler6536 2 жыл бұрын
There's a good reason why no one knows how to write regex: _they're garbage._ The old joke about "now you have two problems" exists for a good reason. If your use case is simple, it's more readable, and likely to be both more performant and less buggy, to write some manual string-parsing code. If your use case is not simple, it's more readable, and almost certain to be less buggy, to use a parser generator such as ANTLR. Regex was a cool trick back in the 80s and early 90s, but we've had significantly better alternatives for a long time now. Please don't go inflicting regex on people who might need to read and maintain your code in the future. (Especially because you might well be one of them!)
@arjix8738
@arjix8738 2 жыл бұрын
Hey! I know how to write regex!
@nickchapsas
@nickchapsas 2 жыл бұрын
Stop lying
@arjix8738
@arjix8738 2 жыл бұрын
@@nickchapsas I am not lying, I practiced a lot! Honestly, writing regex is easy, reading regex is the hard part. And comprehending regex that was not written by urself is even harder
@davidwhite2011
@davidwhite2011 2 жыл бұрын
2nd
@lx2222x
@lx2222x 2 жыл бұрын
This is why C# is way better than JS
@stdprocedure
@stdprocedure 2 жыл бұрын
imagine rust's macros in c#
@ghostaccount9865
@ghostaccount9865 2 жыл бұрын
Microsoft and flipping tables on all the other languages and technologies out there. Bravo! . But when am I going to be a developer for God sake ?
@augustobarreto5301
@augustobarreto5301 2 жыл бұрын
The attribute name is too big for something so basic
@samuelschwager
@samuelschwager 2 жыл бұрын
Real pros use regex to parse html :P
@ssmcs060
@ssmcs060 2 жыл бұрын
Age 69 🎭 🙂🙃
@petermcraa
@petermcraa 2 жыл бұрын
Wierd, but reminds me of Typescript.
@lordmetzgermeister
@lordmetzgermeister 2 жыл бұрын
Excuse me, "rejex"? Are those "rejular expressions" now? xD
@nickchapsas
@nickchapsas 2 жыл бұрын
The plural of Regex is Regrets
@thebitterbeginning
@thebitterbeginning 2 жыл бұрын
...because no one knows how to write RegEx... lol!
What is the NEW "file" keyword of C# 11?
8:26
Nick Chapsas
Рет қаралды 39 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 149 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН
The fastest way to iterate a List in C# is NOT what you think
13:42
Nick Chapsas
Рет қаралды 159 М.
How To Create Smart Enums in C# With Rich Behavior
17:31
Milan Jovanović
Рет қаралды 57 М.
Why Developers and Companies Hate .NET 9
10:56
Nick Chapsas
Рет қаралды 58 М.
How IEnumerable can kill your performance in C#
11:02
Nick Chapsas
Рет қаралды 120 М.
Car Management System: Complete GO Lang Project
4:40:00
Code Alley with Anurag
Рет қаралды 9 М.
Fixing Your Dictionary Problem in .NET
9:19
Nick Chapsas
Рет қаралды 13 М.
How to Build Effective AI Agents (without the hype)
24:27
Dave Ebbelaar
Рет қаралды 34 М.
Writing C# without allocating ANY memory
19:36
Nick Chapsas
Рет қаралды 154 М.
Stop using LINQ to order your primitive collections in C#
14:57
Nick Chapsas
Рет қаралды 98 М.
Every single feature of C# in 10 minutes
9:50
Train To Code
Рет қаралды 169 М.