C
C#ā€¢11mo ago
Groophy

I can't understand

I'll share code in one minute, please wait.
No description
71 Replies
Groophy
GroophyOPā€¢11mo ago
VarriableStorage.cs
c#
internal class VarriableStorage<T>
{
private T _value;

public VarriableStorage(T value)
=> _value = value;

public void Set(T value)
=> _value = value;

public T Get()
=> _value;
}
c#
internal class VarriableStorage<T>
{
private T _value;

public VarriableStorage(T value)
=> _value = value;

public void Set(T value)
=> _value = value;

public T Get()
=> _value;
}
Hooks.cs
c#
public static class Hooks
{
public static (Func<T>, Action<T>) useState<T>(T value)
{
var storage = new VarriableStorage<T>(value);
var set = new Action<T>(val => storage.Set(val));
var get = new Func<T>(() => storage.Get());

return (get, set);
}
}
c#
public static class Hooks
{
public static (Func<T>, Action<T>) useState<T>(T value)
{
var storage = new VarriableStorage<T>(value);
var set = new Action<T>(val => storage.Set(val));
var get = new Func<T>(() => storage.Get());

return (get, set);
}
}
Homepage.cs
c#
internal class Homepage : Page
{
private (count, setCount) = Hooks.useState<int>(5); // ERRORS IN HERE

public override string Response()
{
return "";
}
}
c#
internal class Homepage : Page
{
private (count, setCount) = Hooks.useState<int>(5); // ERRORS IN HERE

public override string Response()
{
return "";
}
}
Groophy
GroophyOPā€¢11mo ago
No description
Groophy
GroophyOPā€¢11mo ago
In code highlight as
No description
Groophy
GroophyOPā€¢11mo ago
I can't understand why And yeah I'm trying to steal react
Angius
Angiusā€¢11mo ago
I don't think you can do tuple deconstruction in a field
Groophy
GroophyOPā€¢11mo ago
do you have a suggestion?
Angius
Angiusā€¢11mo ago
Not really
Thinker
Thinkerā€¢11mo ago
Set them in a constructor
Angius
Angiusā€¢11mo ago
As a side note,
var set = new Action<T>(val => storage.Set(val));
var get = new Func<T>(() => storage.Get());
var set = new Action<T>(val => storage.Set(val));
var get = new Func<T>(() => storage.Get());
can just be
var set = val => storage.Set(val);
var get = () => storage.Get();
var set = val => storage.Set(val);
var get = () => storage.Get();
Thinker
Thinkerā€¢11mo ago
private int count;
private Action<int> setCount;

public HomePage()
{
(count, setCount) = Hooks.useState<int>(5);
}
private int count;
private Action<int> setCount;

public HomePage()
{
(count, setCount) = Hooks.useState<int>(5);
}
Groophy
GroophyOPā€¢11mo ago
I tried and seems worked
No description
Angius
Angiusā€¢11mo ago
Ah, or that Right... there's no var in fields, but if you type those explicitly, sure I can see why it works Nice
Groophy
GroophyOPā€¢11mo ago
var set = val => storage.Set(val); cause error but second works as I remember
Thinker
Thinkerā€¢11mo ago
yeah you'd have to specify the type of val
Groophy
GroophyOPā€¢11mo ago
It's really bad developer experience for what I want
Angius
Angiusā€¢11mo ago
Well, it will be
Thinker
Thinkerā€¢11mo ago
var set = (int val) => storage.Set(val);
Angius
Angiusā€¢11mo ago
You're trying to bring mechanisms from an untyped language to a typed one lol There will be friction
Groophy
GroophyOPā€¢11mo ago
I think I made a mistake before and now it works. I love C# I hate asp.net I like JS I love React Architecture Why I'm not making my own csx? šŸ˜„
Angius
Angiusā€¢11mo ago
Or you could use React frontend with an ASP API backend ĀÆ\_(惄)_/ĀÆ But sure, I guess this is a nice exercise as well Just... use naming convention propert for C# please lol
Groophy
GroophyOPā€¢11mo ago
Yeah I have my own library for that, which not require asp.net APIs
Groophy
GroophyOPā€¢11mo ago
GitHub
GitHub - GroophyLifefor/ExpressNET
Contribute to GroophyLifefor/ExpressNET development by creating an account on GitHub.
Angius
Angiusā€¢11mo ago
Ah So you reinvented Minimal APIs I see
Groophy
GroophyOPā€¢11mo ago
I don't understand as well
Angius
Angiusā€¢11mo ago
Method names are PascalCase, for example Not camelCase
Groophy
GroophyOPā€¢11mo ago
Of course, at the time I didn't know there was such a thing, but it was a good experience and it works really well. šŸ„²
Thinker
Thinkerā€¢11mo ago
You can do this in ASP.NET
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.Run();
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.Run();
this is a working API
Groophy
GroophyOPā€¢11mo ago
as In my experience camelCase really good in C# too I don't reject it šŸ˜„
Thinker
Thinkerā€¢11mo ago
don't šŸ‘ use šŸ‘ camelCase šŸ‘ for šŸ‘ methods šŸ‘ in šŸ‘ c# šŸ‘
Angius
Angiusā€¢11mo ago
As in the standard, camelCase no good in C#
Groophy
GroophyOPā€¢11mo ago
I don't understand why C# community hates camelCase
Thinker
Thinkerā€¢11mo ago
because C# uses PascalCase for methods
Angius
Angiusā€¢11mo ago
It's the standard. Every codebase follows it
Thinker
Thinkerā€¢11mo ago
(besides Unity)
Angius
Angiusā€¢11mo ago
It's not about loving or hating, it's about standardization
Thinker
Thinkerā€¢11mo ago
Just stop arguing and accept that this is how C# is
Groophy
GroophyOPā€¢11mo ago
In js some devs use PascalCase and I don't care but if I use camelCase in c#
Angius
Angiusā€¢11mo ago
Because JS has fuck all for standards lmao
Groophy
GroophyOPā€¢11mo ago
people get angry to me
Angius
Angiusā€¢11mo ago
JS is the definition of a free-for-all No types, no standards, no core library
Groophy
GroophyOPā€¢11mo ago
It's absurd This should be developer preference if you don't work in a company
Thinker
Thinkerā€¢11mo ago
If you want your code to be inconsistent with the rest of C#, then be my guest Everything else in C# uses PascalCase, it's your choice to be the outlier in that case
Angius
Angiusā€¢11mo ago
Again, it ensures consistency
Groophy
GroophyOPā€¢11mo ago
Will I really be ostracized for this choice?
Angius
Angiusā€¢11mo ago
Yes
Thinker
Thinkerā€¢11mo ago
Yes
Groophy
GroophyOPā€¢11mo ago
Please don't go crazy, it's not that important
Angius
Angiusā€¢11mo ago
Standards are important. Otherwise we would see
var thing = some_lib_thing();
thing.do_stuff();
var foo = foo.Parse(thing);
foo.performAction().some-property;
var thing = some_lib_thing();
thing.do_stuff();
var foo = foo.Parse(thing);
foo.performAction().some-property;
PHP was struggling with it ā€” still is ā€” for the longest time
Thinker
Thinkerā€¢11mo ago
Also what's almost even worse is that you're inconsistent with naming in your own codebase. Some methods are PascalCase, some are camelCase.
Angius
Angiusā€¢11mo ago
Where some functions were pascalCase() while some were snake_case()
Groophy
GroophyOPā€¢11mo ago
The reason for this was that I wanted to keep the ones in the user base in PascalCase, while the ones from the core in camelCase. where I use snake_case?
Angius
Angiusā€¢11mo ago
Nowhere I'm just talking about standards Without them, you would have one codebase using snake_case, another camelCase, another one kebab-case
Groophy
GroophyOPā€¢11mo ago
uhm
Angius
Angiusā€¢11mo ago
And every project would just look like a mishmash of all sorts of styles With standards, I know that thing.Foo is a property Because it's PascalCased And I know, that this.foo is a field Because it's camelCase
Groophy
GroophyOPā€¢11mo ago
I know why and what the standards are, it just doesn't make sense.
Angius
Angiusā€¢11mo ago
With standards, every method is named the same No matter whether it's my codebase or someone else's
Groophy
GroophyOPā€¢11mo ago
_
Angius
Angiusā€¢11mo ago
It could be Microsoft's huge framework, it could be a 50-loc project with 0 GH stars It's all consistent and standardized It should be manufacturer's preference which charging port they use in their devices That's how we had a different charger for every phone Not just phone manufacturer, phone model
Thinker
Thinkerā€¢11mo ago
What about it doesn't make sense exactly?
Angius
Angiusā€¢11mo ago
Now it's standardized ā€” in the EU at least ā€” USB-C That way you can be certain that no matter whose device you buy, the charging port is the same Again, standardization
Groophy
GroophyOPā€¢11mo ago
Having such a standard As I said, a lot of things can be standard, but I think this is something that should be a developer choice.
Angius
Angiusā€¢11mo ago
But isn't
mg
mgā€¢11mo ago
You do have a choice to contradict the standard Your code will compile just fine
Angius
Angiusā€¢11mo ago
So either deal with it or be an outlier Your choice
mg
mgā€¢11mo ago
But people will criticize you for it
Groophy
GroophyOPā€¢11mo ago
as now šŸ˜„
Thinker
Thinkerā€¢11mo ago
Also (idk what this thread is even about at this point), I'm looking through your code and am seeing you're using async void in a couple places. Don't do this, everything which is async should return a Task or Task<T>.
-public async void Listen(string path, Action<int>? action)
+public async Task Listen(string path, Action<int>? action)
-public async void Listen(string path, Action<int>? action)
+public async Task Listen(string path, Action<int>? action)
mg
mgā€¢11mo ago
Exactly lol
Groophy
GroophyOPā€¢11mo ago
Thanks you I'll Done Maybe you are right, I will think about switching to PascalCase
Angius
Angiusā€¢11mo ago
You refactor your code quickly, if you managed to fix all occurences of async void this quickly, complete with awaiting all calls to those methods and all KEKW
Groophy
GroophyOPā€¢11mo ago
it's not hard It's just my bad which 'Result<Thinker>' said and I gonna fixed
Want results from more Discord servers?
Add your server