Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Presto
Nov 22, 2002

Keep calm and Harry on.

Athas posted:

I'm surprised what in SML wouldn't make sense to an entirely new programmer.

I wasn't a new programmer. It still didn't make sense. But then, I just don't get functional languages in general.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

Athas posted:

Nowadays they use F# for that course, primarily because it merged with a subsequent OOP course, and they wanted to stick to a single language. Also, SML is more or less dead.

Whoa, I wasn’t aware that anywhere taught F#. Are comfortable sharing anything about the specific institution?

QuarkJets
Sep 8, 2008

If you're a mediocre programmer you use C#, if you're a failed programmer you use F#

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
if you're a programmer who's frustrated about having nothing better to do you post broad statements about programming languages you dislike

Absurd Alhazred
Mar 27, 2010

by Athanatos
Programming only leads to bugs. Every language. Doesn't matter.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Absurd Alhazred posted:

Programming only leads to bugs. Every language. Doesn't matter.

not only, but yes, inevitably

QuarkJets
Sep 8, 2008

I don't dislike C# or F# just stating some facts

The best language would be A#

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
You're all wrong, the best programming language is English, for responsibly writing good documentation.

Impotence
Nov 8, 2010
Lipstick Apathy
My PHP is self documenting

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Happy Thread posted:

You're all wrong, the best programming language is English, for responsibly writing good documentation.

Uh, Esperanto, like, right over here. Just saying.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

raminasi posted:

Whoa, I wasn’t aware that anywhere taught F#. Are comfortable sharing anything about the specific institution?

Several universities in Europe teach it to undergrads.

Athas
Aug 6, 2007

fuck that joker

raminasi posted:

Whoa, I wasn’t aware that anywhere taught F#. Are comfortable sharing anything about the specific institution?

University of Copenhagen, but I think there are many places that teach F#.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Volmarias posted:

Uh, Esperanto, like, right over here. Just saying.

You misspelled Prolog Lojban.

Presto
Nov 22, 2002

Keep calm and Harry on.

Happy Thread posted:

You're all wrong, the best programming language is English, for responsibly writing good documentation.

Good what?

Soricidus
Oct 21, 2010
freedom-hating statist shill

Presto posted:

Good what?

You know, comments like “DO NOT REMOVE” and “temporary hack 12/8/2005” and “here be dragons”. Documentation.

Kazinsal
Dec 13, 2011

Soricidus posted:

You know, comments like “DO NOT REMOVE” and “temporary hack 12/8/2005” and “here be dragons”. Documentation.

// XXX - gently caress

Xarn
Jun 26, 2015
TIL the assumption that Sunday is the start of the week is literally hardcoded into the C# standard library.

Thanks Microsoft :v:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Xarn posted:

TIL the assumption that Sunday is the start of the week is literally hardcoded into the C# standard library.

Thanks Microsoft :v:

I haven't ever had to write any C# code that cares what the "start of the week is" but it seems to be based on cultures? which seems sensible?

code:
namespace dayofweek
{
    class Program
    {
        static void Main(string[] args)
        {
            var invariant = CultureInfo.InvariantCulture.DateTimeFormat.FirstDayOfWeek;
            var current = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
            var currentUi = CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek;

            Console.WriteLine(invariant);
            Console.WriteLine(current);
            Console.WriteLine(currentUi);
        }
    }
}

quote:

Sunday
Monday
Monday

Vanadium
Jan 8, 2005

we considered ourselves an invariant culture

Tei
Feb 19, 2011

Today I found a new one.

A login web form sending the credentials with GET.

Volte
Oct 4, 2004

woosh woosh

Tei posted:

Today I found a new one.

A login web form sending the credentials with GET.
I was once hired to fix a site that kept getting "hacked" and that's what it was doing. It also didn't actually check the password so you could type anything and it would still log you in. The login form was a placeholder that was generated by Dreamweaver.

NtotheTC
Dec 31, 2007


Tei posted:

Today I found a new one.

A login web form sending the credentials with GET.

It's testing friendly!

Last place I worked at had multiple GET requests that updated DB rows, and even had comments along the lines of "we shouldn't be doing this but..."

Xarn
Jun 26, 2015

Hammerite posted:

I haven't ever had to write any C# code that cares what the "start of the week is" but it seems to be based on cultures? which seems sensible?

code:
namespace dayofweek
{
    class Program
    {
        static void Main(string[] args)
        {
            var invariant = CultureInfo.InvariantCulture.DateTimeFormat.FirstDayOfWeek;
            var current = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
            var currentUi = CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek;

            Console.WriteLine(invariant);
            Console.WriteLine(current);
            Console.WriteLine(currentUi);
        }
    }
}

https://docs.microsoft.com/en-us/dotnet/api/system.dayofweek?view=net-5.0

(Also lol at listing the fields in alphabetical format)

Tei
Feb 19, 2011

Volte posted:

I was once hired to fix a site that kept getting "hacked" and that's what it was doing. It also didn't actually check the password so you could type anything and it would still log you in. The login form was a placeholder that was generated by Dreamweaver.

https://twitter.com/SwiftOnSecurity/status/1359444877751246850

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
They really should have made the day of week enum be assigned values like, 37-43, with the lowest number being Thursday, just to make it blindingly obvious that you should be using the localization facilities to turn it into user-relevant stuff instead of goofing around with the numbers directly.

Xarn
Jun 26, 2015
Not sure if C# enums support it, but the best solution would be to say "nope, not convertible to numbers, get lost".

Space Gopher
Jul 31, 2006

BLITHERING IDIOT AND HARDCORE DURIAN APOLOGIST. LET ME TELL YOU WHY THIS SHIT DON'T STINK EVEN THOUGH WE ALL KNOW IT DOES BECAUSE I'M SUPER CULTURED.

Xarn posted:

Not sure if C# enums support it, but the best solution would be to say "nope, not convertible to numbers, get lost".

The C# spec defines enums as backed by an integral type.

It’s always going to be a number in one way or another. That’s how computers work. The UTF-8 string literal “Friday” interpreted as a big-endian unsigned integer is 77,457,208,402,297 - and if that was the spec I’m sure we’d hear people complaining that Microsoft should have used the natural, correct representation of “Vendredi” or “星期五”instead. The entire point of using an enum is that your code doesn’t and shouldn’t need to care how those numbers map to symbolic representations, once you’re past serialization and hardware boundaries.

If you ever find yourself doing arithmetic operations on enum values in a high-level language, that’s a good sign to stop and think really hard about what you’re doing. And, if you ever find yourself directly operating on internal representations of date or time values, just stop. You’re lucky that you just got frustrated that the invariant culture didn’t match your assumptions instead of creating a subtle bug out of some weird calendar trivia question.

Absurd Alhazred
Mar 27, 2010

by Athanatos

Space Gopher posted:

The C# spec defines enums as backed by an integral type.

It’s always going to be a number in one way or another. That’s how computers work. The UTF-8 string literal “Friday” interpreted as a big-endian unsigned integer is 77,457,208,402,297 - and if that was the spec I’m sure we’d hear people complaining that Microsoft should have used the natural, correct representation of “Vendredi” or “星期五”instead. The entire point of using an enum is that your code doesn’t and shouldn’t need to care how those numbers map to symbolic representations, once you’re past serialization and hardware boundaries.

If you ever find yourself doing arithmetic operations on enum values in a high-level language, that’s a good sign to stop and think really hard about what you’re doing. And, if you ever find yourself directly operating on internal representations of date or time values, just stop. You’re lucky that you just got frustrated that the invariant culture didn’t match your assumptions instead of creating a subtle bug out of some weird calendar trivia question.

C++ lets you declare enum class which forces you to actively cast to an integer to do any arithmetic on it, which helps.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Xarn posted:

https://docs.microsoft.com/en-us/dotnet/api/system.dayofweek?view=net-5.0

(Also lol at listing the fields in alphabetical format)

That does not mean that the first day of the week is hardcoded to be Sunday. It just means that Sunday is hardcoded to be the first field in the enum. As Hammerite mentioned, the culture defines what the first day of the week is, not the enum. Given that they chose to use an enum, this is literally the only way they could have done it (other than starting the enum at a different day, of course).

All .NET enums are always convertible to some integer type, so there's no way to prevent people from converting it to a number. You could opt to not explicitly set the backing value in the enum, but then .NET will just implicitly give the enum fields a value.

Jabor's suggestion is really the only thing they could have done to make it harder for people to do the wrong thing, but even that wouldn't have prevented it. I guess they could've also opted to give the fields random values that change between every .NET release, but that would probably have caused MS more issues that it would ever solve.

Since the addition of extension methods, they could've also added a culture sensitive extension method that returns the "number" of the day of the week, which would've been nice. Granted if someone needs that, it's quite easy to just implement.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Absurd Alhazred posted:

C++ lets you declare enum class which forces you to actively cast to an integer to do any arithmetic on it, which helps.

It's the same in C#, you can't preform arithmetic on an enum directly, you'd have to cast it first. And, iirc, in order to do that, you need to know which integer type is the backing type, e.g. if you cast an enum to a short while it's backed by an int, you get a runtime exception.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Should do it like hash seeds and randomize calendar enum values each launch. That'll learn ya.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Does C# let you do order comparisons on enums without casting them? If so, that's a big part of the problem.

Absurd Alhazred
Mar 27, 2010

by Athanatos

pokeyman posted:

Should do it like hash seeds and randomize calendar enum values each launch. That'll learn ya.

Talk about backwards combatability!

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

ultrafilter posted:

Does C# let you do order comparisons on enums without casting them? If so, that's a big part of the problem.

Yes, it does. As you'd expect it just compares the backing values.

Space Gopher
Jul 31, 2006

BLITHERING IDIOT AND HARDCORE DURIAN APOLOGIST. LET ME TELL YOU WHY THIS SHIT DON'T STINK EVEN THOUGH WE ALL KNOW IT DOES BECAUSE I'M SUPER CULTURED.

dwazegek posted:

It's the same in C#, you can't preform arithmetic on an enum directly, you'd have to cast it first. And, iirc, in order to do that, you need to know which integer type is the backing type, e.g. if you cast an enum to a short while it's backed by an int, you get a runtime exception.

Enums in C# directly support comparisons, bitwise operators, addition, and subtraction.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/enums#enum-values-and-operations

There are places where this is useful, especially the bitwise operators, but if you find yourself doing it, it’s a real good time to stop and double-check that it’s the best approach.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I am having difficulty imagining a situation where you would want to know the underlying numerical values of a "days of the week" enum, or be tempted to compare them numerically, add or subtract them, etc.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


If you want to know whether today is before Thursday, and you're not thinking clearly, you might be tempted to do that comparison with <.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Tei posted:

Today I found a new one.

A login web form sending the credentials with GET.

I have seen a payment processor that sends payment details (Cc and all) as an "image" request. This was last year.

xtal
Jan 9, 2011

by Fluffdaddy

Tei posted:

Today I found a new one.

A login web form sending the credentials with GET.

Private Internet Access (the VPN) used to do this

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015

pokeyman posted:

Should do it like hash seeds and randomize calendar enum values each launch. That'll learn ya.

This is unironically the correct answer. The other alternative is to embrace being a high level language and disallow accessing the underlying bit representation. This even has the advantage of letting the compiler optimize it as needed.



Space Gopher posted:

You’re lucky that you just got frustrated that the invariant culture didn’t match your assumptions instead of creating a subtle bug out of some weird calendar trivia question.

No, I am currently disentangling piece of code that has 0 tests and is tangentially related in a sev 2 production incident. It starts by converting a MonthOfDay + start time as utc into a linear representation of time in a week :v:

(This is actually not the bug, and the code in question does not depend on which day starts the week, but I am still not amused by the current state)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply