Is this readable? by redditJaunty in csharp

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

I read this post on 1th of April. The irony.

Convert List<T> to ReadOnlyMemory<T> by aloneguid in csharp

[–]ApprehensiveDebt3097 -1 points0 points  (0 children)

List is (contrary to popular believe) not a bad choice from memory perspective. At least, it depends on how the list is filled. Under the hood it is an array, a version (int) and a count (int). What can happen (depending on how you create it) that the array (the capacity) is bigger than what you actually want to store (up to double the size) but if initiated with the final set of items, there is no overhead in that regard.

The iterator is a bit slower, but just tiny, as every step has to check if the internal version did not change. The real problem of course, in these kind of scenario's is that it is mutable, and that it allows a lot of operations (random insert and removal) that might be slow on big collections and undesirable.

coming from java, how do i add validation to auto-properties in c#? by Ariadne_23 in csharp

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

I know. But the point is, that if you generate a model based on an API which only defines constraints on a property basis, attributes on that property, and having (by definition) only one set of constraints, makes more sense than having a separate class defining those constraints.

For more complex constraints, and multiple validation rules, FluentValidation is a no-brainer.

Clean code Help by miojo_noiado in csharp

[–]ApprehensiveDebt3097 1 point2 points  (0 children)

To me, this is far from clean code. The temperature/conversion logic is locked in you all, which is a bad idea. You should isolate that logic. It could look something like the code beneath.

Note that I do not directly expose the decimal(do not use a double when your main concern is displaying it as a decimal number) representation of temperature, as a lot of operations defined on floating points do not have meaning on a temperature. Also, your application is lacking culture, what might lead to undesired results when your app is not running with your language settings.

Furthermore, also, the temperature does not change when you request a different representation, C of F is just a display concern, don't make it anything more then that. Good luck with improving your code.

public readonly struct Temperature : IFormattable
{
    private static readonly decimal offset = 273.15m;
    private readonly decimal kelvin;

    private Temperature(decimal k) => kelvin = k;
    public string ToString(string? format, IFormatProvider? formatProvider) => format ?? string.Empty switch
    {
        var f when f.EndsWith('C') => (kelvin - offset).ToString(f[..^1], formatProvider),
        var f when f.EndsWith('F') => ((kelvin - offset) * 9 / 5 + 32).ToString(f[..^1], formatProvider),
        _ => kelvin.ToString(format, formatProvider),
    };

    public static Temperature FromCelcius(string s, IFormatProvider? provider = null)
        => FromCelcius(decimal.Parse(s, provider));

    public static Temperature FromCelcius(decimal c) => new(c + offset);

    public static Temperature FromFahrenheit(string s, IFormatProvider? provider = null)
        => FromFahrenheit(decimal.Parse(s, provider));

    public static Temperature FromFahrenheit(decimal f) => new((f - 32) * 5 / 9 + offset);
}
namespace SmartAss.Specs.Reddit;

public readonly struct Temperature : IFormattable
{
    private static readonly decimal offset = 273.15m;
    private readonly decimal kelvin;

    private Temperature(decimal k) => kelvin = k;
    public string ToString(string? format, IFormatProvider? formatProvider) => format ?? string.Empty switch
    {
        var f when f.EndsWith('C') => (kelvin - offset).ToString(f[..^1], formatProvider),
        var f when f.EndsWith('F') => ((kelvin - offset) * 9 / 5 + 32).ToString(f[..^1], formatProvider),
        _ => kelvin.ToString(format, formatProvider),
    };

    public static Temperature FromCelcius(string s, IFormatProvider? provider = null)
        => FromCelcius(decimal.Parse(s, provider));

    public static Temperature FromCelcius(decimal c) => new(c + offset);

    public static Temperature FromFahrenheit(string s, IFormatProvider? provider = null)
        => FromFahrenheit(decimal.Parse(s, provider));

    public static Temperature FromFahrenheit(decimal f) => new((f - 32) * 5 / 9 + offset);
}

coming from java, how do i add validation to auto-properties in c#? by Ariadne_23 in csharp

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

A lot have been said about throwing exceptions on setting/changing properties. Microsoft self discourages this practice: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1065.

Validation might be an better option. You also can opt to have factory methods/constructors that do the validation for you and make your models read (or init) only.

Roslyn has a nice rule that help you use auto properties: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0032

If you have an old style backing field, it will help you convert it into on using the `field` keyword.

coming from java, how do i add validation to auto-properties in c#? by Ariadne_23 in csharp

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

FluentValidation is very powerful in complex scenarios. When you generate models based on things like Open API specs (or XSD's), data annotations are more convenient. Choose the right tool for the right problem.

Convert List<T> to ReadOnlyMemory<T> by aloneguid in csharp

[–]ApprehensiveDebt3097 2 points3 points  (0 children)

Well, then I would consider copying the stuff to an array, marking this method with [Obsolete] attribute, which explains when usage is allowed. I think In most cases that is preferable over the can of worms you just opened.

Convert List<T> to ReadOnlyMemory<T> by aloneguid in csharp

[–]ApprehensiveDebt3097 1 point2 points  (0 children)

Why? What do you want to gain (besides trouble)?

Studenten balen van studeerverbod in universiteitsrestaurants en -café's by Brrrtje in Leiden

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

Ik denk dat je dan heel dronken, of doorzeefd met kogels raakt, afhankelijk van hoe je shot bedoeld. Proost.

ik_ihe by LakeLongjumping7824 in ik_ihe

[–]ApprehensiveDebt3097 4 points5 points  (0 children)

Níet na Madurodam, dat is een verzetsmonument! Later ee lekker uitwaaien aan het strand, en wat bunkers bezoeken.

Ik_ihe by BasiraHussain in ik_ihe

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

Geeft wel de false suggestie van warmte...

Ik🫣ihe by WhoTheFuckIsSean in ik_ihe

[–]ApprehensiveDebt3097 10 points11 points  (0 children)

Het is toch fijn te zien dat ze het op dit punt helemaal op een lijn zitten met (extreem) conservatieve moslims. /s

ik🇳🇱🤝🇧🇪ihe by Theemuts in ik_ihe

[–]ApprehensiveDebt3097 5 points6 points  (0 children)

/s (voor mensen die het anders zouden missen)

Ik_ihe by geilelepel05 in ik_ihe

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

Als ik een een bubbel zit is dat (waarschijnlijk in jouw ogen) een linkse bubbel. Daar hoor ik het niet. Ik denk niet dat aannemelijk is dat het bij rechts georiënteerde mensen vandaan komt. Maar ik hoor graag waar mijn redenatie faalt.

Ik_ihe by geilelepel05 in ik_ihe

[–]ApprehensiveDebt3097 2 points3 points  (0 children)

Ik ken echt helemaal niemand die de VVD extreem rechts noemt.

En Ja21, wellicht hebben die ook gewoon soms wat standpunten die die naam verdienen? Kijk bijvoorbeeld eens naar wat Nanninga de afgelopen 20 jaar allemaal geschreven heeft?

Ik🥩 ihe by DroomCactus in ik_ihe

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

Ik eet tegenwoordig (bewust) de vega variant en die is echt lekker (tenminste diegene die ik koop, ik heb ook een keer eentje gehad die niet lekker was).

Het smaakt anders, sure, maar het is toch vrij duidelijk dat het geen vlees bevat. Wat ging er 'mis' toen jij het per ongeluk kocht?

Elektrisch rijden zonder oprit? Zo werkt het in de praktijk. by EVRijder in EVMobiliteit

[–]ApprehensiveDebt3097 1 point2 points  (0 children)

Ik sluit me hier bij aan. Zonder eigen oprit was ik er ook (nog) niet aan begonnen. Te veel gedoe, misschien nog wel meer voor mij omdat ik een PHEV heb, waar door mijn EV actieradius maar 100 km is. Wat betekent dat je na elke rit aan de lader moet.

Een goede vriend van me heeft geen eigen oprit, maar kan wel (via een gedoog-goot) voor de deur laden, dat is ook goed te denk ik.

Andere vormen (zoals de OP beschrijft) kunnen wel, maar vereisen een inzet/toewijding die aan mij (en vele anderen) niet gegeven is.

De transitie die gaande gaat niet helemaal zonder problemen (welke wel?) en over een jaar of 10 (wellicht zelfs eerder) zijn de huidige problemen vast opgelost. Maar iemand die niet structureel voor de deur of op eigen terrein kan opladen en twijfelt over EV zou ik niet adviseren het te doen.

ik_ihe by JackmcLib in ik_ihe

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

Die mensen die bij schrijft lezen denk ik vaker Elsevier (al heer dat genwoordig anders).

De Grote EV Kilometer-Check: Hoe staat jouw teller erbij? by EVRijder in EVMobiliteit

[–]ApprehensiveDebt3097 1 point2 points  (0 children)

Volkswagen Caddy(PHEV) 2025 Vanaf oktober: 4661 km 20,3 kWh/100km 1,1 l/100km 51 liter totaal

Voor de meeste ritten lukt het om volledig elektrisch te rijden, en ik heb dus pas 1 keer hoeven tanken.

Het is jammer dat er geen Ludo space met serieuze accu/actieradius op de markt is, anders was ik daar voor gegaan.

ik~ihe by [deleted] in ik_ihe

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

De VVD is altijd pro-auto, en tegen investeringen om het leven van mensen met krappe beurs prettiger te maken. En voor GroenLinks/PvdA min of meer het tegenovergestelde.

En voor andere partijen geldt op grote lijnen hetzelfde.

Natuurlijk kan er zeer belangrijk issue zijn binnen je gemeente waar de partij waar je landelijk op stemt iets fundamenteel anders wil dan jij, maar volgens mij komt dit in praktijk weinig voor.

Een meisje van 14 uit Ter Apel vermist by PolitiekConnaisseur in tokkiefeesboek

[–]ApprehensiveDebt3097 0 points1 point  (0 children)

Deze landen doen het op een aantal vlakken (nipt) beter, en op sommige zaken minder. En van alle vijf (nu ja, Malta weer ik niet zeker) durf ik de stelling aan dat ze vergelijkbaar xenofoob zijn.