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.
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 🤣
@@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…
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.
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!
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."
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.
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.
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!
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.
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.
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.
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)
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.
@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!
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
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.
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.
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)
@@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.
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.
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.
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.
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 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
@@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. 🙂
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 !
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.
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.
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?
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.
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.
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.
@@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.
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
@@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
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 😄
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!)
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.
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 🤣
I am no one.
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....
@@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…
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.
@@modernkennnern yup, that’s almost entirely where I actually use regex. Find and replace
I was chanting "Attribute Attribute Attribute" for about 3 minutes until the reveal :D Happy they went this way.
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!
I have never seen a more useful programming channel. Thank you.
omg this is crazy. this is crazy!!! as a library dev this is an absolute gamechanger for me. wow wow wow
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."
Oh wow, that is beautiful. And timely too because my current project uses Regexes a lot. Nice!
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.
1:03 truer words have never been spoken
I’m glad the argument is a string so custom formats can be written. I wanna see XPath syntax highlighting
Holy smokes, that's a pretty cool feature and I can see it becoming better and better with time.
Thanks, Nick!
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.
Rider has some support for recognizing SQL strings.
Oh my god if they add support for SQL and HTML I would literally cry of joy (and demand my company upgrade to Net7)
JetBrains' Annotations has had RegexPatternAttribute for aaaages which does this same thing. Glad it's standardised and supporting other syntaxes
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!
It's would be pretty cool. I assume this can be done with a VS Extension or a RIder Plugin
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.
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.
Wow, this was really useful. Thanks Nick!
Awesome feature, thanks for showing!
I love Nick's number examples
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.
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)
A really cool and handy thing! Thanks for the heads up
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.
@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!
Thank you! Great feature!
Ooookay .. that's a cool feature, indeed! Thank you for sharing this.
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
Reminds me of TypeScript's awesome template literal feature. So excited to see this validation added in Rider!
Thanks, Nick.
Very informative and helpful. Thx.
Wow that is super sweet. Thank you!😊
Will be interesting to see custom implementations.
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.
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.
Thanks for the great video!
"No one knows how to write Regex" This is so true 😭
Thanks for putting out all these great content 🙏🏽
"No one knows how to write Regex"
*timidly raises hand*
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)
You can write something like this with 'using' keyword:
using NullableInt = System.Nullable;
I don't know if it works with attributes.
Seriously, the attribute being long is getting out of hand.
in C# there's nothing even remotely similar to what you suggest so that would be hard to do
@@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.
Wow, cool feature. Makes stringly typed data just a little safer to use.
Thanks nick.
I love this feature
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.
Killer. Thanks!
Cool feature. ReSharper has had it for years ;-)
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.
It will come in handy. Do you know if we could create custom string sintaxes?
This is great!
Interesting. Using this properly eliminates an entire class of possible mistakes.
Video gets nice @ 6:14
Wow ! thats nice
1:02 deep truth
Nice! Very nice!
It's very cool. Can we customize this, for example json format fix warning etc.
Nice one
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.
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)]"
@@jackoberto01 he is saying that what’s in the parentheses is too long
@@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
@@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. 🙂
1:04 absolutely, Lol 😂😆
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?
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 :)
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 !
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.
"No-one knows how to write regex" I haven't laughed that hard since your goPilot video!
Are we not going to argue about the way he pronounces regex? No? Alright.
Anyway, great feature! I'm looking forward to using it 😊
The original plan was to pronounce it both regex and regex but I forgot to switch it up mid-video
I was wondering as well. Surprised there's only one comment here...
Anyway it's "rejular expressions" now.
Is it possible to create custom syntax attributes in which you can create your own list of "options" to fill?
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.
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?
1:05 Nick Chapsas: No one knows how to write regex
Experienced Perl programmer: *HOLD MY BEER.*
Hi Nick,
Can you make a video about IAsyncEnumerable plz?
Can this attribute be applied to fields/consts?
Thanks for the sub-10 minute video. I feel smarter quicker
🔥
61 years old and just purchased tNice tutorials software. i love making my own soft
It would be cool to have SQL support
Is it possible to define own syntax?
Hi
A simple question. Can Net 7 RC be used in production ? and is it drop in replacement for Net 6.
I would not run any RC version in production. Wait for the full release. It will mostly be a drop in replacement
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.
What is the state of c# 7? When will it be released?
C# 7 was released in 2017. I guess you mean .NET 7? November 2022
Praying dotnet will have a good Uri parser one day.
My question is: will this attribute compile into the binary?
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.
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.
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.
@@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.
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
I had no idea the IDE changed behaviour based on comments.
Attribute length is getting out of hand, C# need to have type alias
1:03 lol
When you opened VS...
Mood.
This is crazy!! You look so much younger than 69!
I use sun screen
Could they have made those annotations any more verbose? They take up more space than the method signatures themselves.
You look pretty young for a 69 years old
Hey! I know how to write regex!
Stop lying
@@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
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 😄
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!)
whats up with that double """"?
It's a new C# 11 feature called, raw string literals.
@@nickchapsas I saw a cool video about that feature here th-cam.com/video/4KXWAgZE8xI/w-d-xo.html
This is why C# is way better than JS
imagine rust's macros in c#
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 ?
2nd
Real pros use regex to parse html :P
Age 69 🎭 🙂🙃
Excuse me, "rejex"? Are those "rejular expressions" now? xD
The plural of Regex is Regrets
The attribute name is too big for something so basic
Wierd, but reminds me of Typescript.
nice, but a bit mouthful