C
C#ā€¢6mo ago
Groophy

I can't understand

I'll share code in one minute, please wait.
No description
71 Replies
Groophy
Groophyā€¢6mo 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
Groophyā€¢6mo ago
No description
Groophy
Groophyā€¢6mo ago
In code highlight as
No description
Groophy
Groophyā€¢6mo ago
I can't understand why And yeah I'm trying to steal react
Angius
Angiusā€¢6mo ago
I don't think you can do tuple deconstruction in a field
Groophy
Groophyā€¢6mo ago
do you have a suggestion?
Angius
Angiusā€¢6mo ago
Not really
Thinker
Thinkerā€¢6mo ago
Set them in a constructor
Angius
Angiusā€¢6mo 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ā€¢6mo 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
Groophyā€¢6mo ago
I tried and seems worked
No description
Angius
Angiusā€¢6mo 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
Groophyā€¢6mo ago
var set = val => storage.Set(val); cause error but second works as I remember
Thinker
Thinkerā€¢6mo ago
yeah you'd have to specify the type of val
Groophy
Groophyā€¢6mo ago
It's really bad developer experience for what I want
Angius
Angiusā€¢6mo ago
Well, it will be
Thinker
Thinkerā€¢6mo ago
var set = (int val) => storage.Set(val);
Angius
Angiusā€¢6mo ago
You're trying to bring mechanisms from an untyped language to a typed one lol There will be friction
Groophy
Groophyā€¢6mo 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ā€¢6mo 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
Groophyā€¢6mo ago
Yeah I have my own library for that, which not require asp.net APIs
Groophy
Groophyā€¢6mo ago
GitHub
GitHub - GroophyLifefor/ExpressNET
Contribute to GroophyLifefor/ExpressNET development by creating an account on GitHub.
Angius
Angiusā€¢6mo ago
Ah So you reinvented Minimal APIs I see
Groophy
Groophyā€¢6mo ago
I don't understand as well
Angius
Angiusā€¢6mo ago
Method names are PascalCase, for example Not camelCase
Groophy
Groophyā€¢6mo 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ā€¢6mo 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
Groophyā€¢6mo ago
as In my experience camelCase really good in C# too I don't reject it šŸ˜„
Thinker
Thinkerā€¢6mo ago
don't šŸ‘ use šŸ‘ camelCase šŸ‘ for šŸ‘ methods šŸ‘ in šŸ‘ c# šŸ‘
Angius
Angiusā€¢6mo ago
As in the standard, camelCase no good in C#
Groophy
Groophyā€¢6mo ago
I don't understand why C# community hates camelCase
Thinker
Thinkerā€¢6mo ago
because C# uses PascalCase for methods
Angius
Angiusā€¢6mo ago
It's the standard. Every codebase follows it
Thinker
Thinkerā€¢6mo ago
(besides Unity)
Angius
Angiusā€¢6mo ago
It's not about loving or hating, it's about standardization
Thinker
Thinkerā€¢6mo ago
Just stop arguing and accept that this is how C# is
Groophy
Groophyā€¢6mo ago
In js some devs use PascalCase and I don't care but if I use camelCase in c#
Angius
Angiusā€¢6mo ago
Because JS has fuck all for standards lmao
Groophy
Groophyā€¢6mo ago
people get angry to me
Angius
Angiusā€¢6mo ago
JS is the definition of a free-for-all No types, no standards, no core library
Groophy
Groophyā€¢6mo ago
It's absurd This should be developer preference if you don't work in a company
Thinker
Thinkerā€¢6mo 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ā€¢6mo ago
Again, it ensures consistency
Groophy
Groophyā€¢6mo ago
Will I really be ostracized for this choice?
Angius
Angiusā€¢6mo ago
Yes
Thinker
Thinkerā€¢6mo ago
Yes
Groophy
Groophyā€¢6mo ago
Please don't go crazy, it's not that important
Angius
Angiusā€¢6mo 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ā€¢6mo 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ā€¢6mo ago
Where some functions were pascalCase() while some were snake_case()
Groophy
Groophyā€¢6mo 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ā€¢6mo 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
Groophyā€¢6mo ago
uhm
Angius
Angiusā€¢6mo 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
Groophyā€¢6mo ago
I know why and what the standards are, it just doesn't make sense.
Angius
Angiusā€¢6mo ago
With standards, every method is named the same No matter whether it's my codebase or someone else's
Groophy
Groophyā€¢6mo ago
_
Angius
Angiusā€¢6mo 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ā€¢6mo ago
What about it doesn't make sense exactly?
Angius
Angiusā€¢6mo 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
Groophyā€¢6mo 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ā€¢6mo ago
But isn't
mg
mgā€¢6mo ago
You do have a choice to contradict the standard Your code will compile just fine
Angius
Angiusā€¢6mo ago
So either deal with it or be an outlier Your choice
mg
mgā€¢6mo ago
But people will criticize you for it
Groophy
Groophyā€¢6mo ago
as now šŸ˜„
Thinker
Thinkerā€¢6mo 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ā€¢6mo ago
Exactly lol
Groophy
Groophyā€¢6mo ago
Thanks you I'll Done Maybe you are right, I will think about switching to PascalCase
Angius
Angiusā€¢6mo 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
Groophyā€¢6mo ago
it's not hard It's just my bad which 'Result<Thinker>' said and I gonna fixed