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
RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

hyphz posted:

Ugh, yes, reference semantics wind me up. We teach languages in the order Python, Java, C/C++ and the Python and Java sessions both elide any mention of the reference model because it’s “too complicated”. Then when the students hit C’s explicit pointers they freak out completely.

my school's CS program taught ARM assembly and C in the first two semesters and made students program an rc car on a cortex m3 chip to drive around a racetrack
at least when you know what a register is and wtf the difference between eax and [eax] is, it's really easy to understand C pointers

Adbot
ADBOT LOVES YOU

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
std::array is not dynamically allocated, that's the whole point of using it over vector

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
Per the article Xarn linked above, go generics are only actually compile-time generics for basic datatypes like int32 / float64.

For every pointer-to-object type, the compiler generates a single dynamic void* implementation shared between all types that looks up the required vtables in a global shared cache at runtime.
This makes it perform worse than just using a non-generic polymorphic function and accepting an interface pointer, since at least for those the vtables are passed in alongside the function arguments.

RPATDO_LAMD fucked around with this message at 01:37 on Jan 9, 2023

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
if your variable names are ambiguous enough to provoke a big annoying argument like this you should ensure there is actual documentation (or at least a comment over the function definition) specifying the actual range of inputs instead of leaving your readers to infer it

because whether you think your side is right or wrong someone from the other side is gonna read your code someday

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Qwertycoatl posted:

I wonder what maintenance problems you get with a giant struct that you don't get wth 26 somewhat less giant structs grouped by name rather than purpose.

It looks like they did it this way so each struct can have its own magic-number sentinel value at the end, letting them check (at runtime) to see whether the struct definition and and its initializer list have gotten out of sync
i guess that's easier than figuring out which entry in a multi-hundred-line struct is missing but it still seems like it could be replaced by a compiler warning flag?

from decl.c:
C code:

#define MAGICCHECK(xx) \
    do {                                                                   \
        if ((xx).magic != IVMAGIC) {                                       \
            raw_printf(                                                    \
                 "decl_globals_init: %s.magic in unexpected state (%lx).", \
                       #xx, (xx).magic);                                   \
            exit(1);                                                       \
        }                                                                  \
        if ((xx).havestate != TRUE) {                                      \
            raw_printf(                                                    \
                 "decl_globals_init: %s.havestate not True.", #xx);        \
            exit(1);                                                       \
        }                                                                  \
    } while(0);
and then:
C code:
    MAGICCHECK(g_init_a);
    MAGICCHECK(g_init_b);
    MAGICCHECK(g_init_c);
[...]
    MAGICCHECK(g_init_x);
    MAGICCHECK(g_init_y);
    MAGICCHECK(g_init_z);

RPATDO_LAMD fucked around with this message at 20:43 on Jan 19, 2023

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

LongSack posted:

I would use a switch expression:
C# code:
return percentage switch {
  0.0 => “…”,
  > 0.0 and <= 1.0 => “…”,
  > 1.0 and <= 2.0 => “…”,
  …
  _ => “…”
}

That's identical to the original dutch-government thing that set this discussion off

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Bruegels Fuckbooks posted:

it's more that it's a high int low wis solution to a problem that probably took a significant amount of work to pull off. someone probably had the thought "hey, what if we just made each OS sleep and had them switch between the two" and then had the balls to keep going when they kept finding problems. doing the amount of work that they did to get this to work and getting a bad result (it's still loving slow to switch between the OS anyway) is a tragedy. i've dealt with engineers that can get anything to "work" given enough time and who would always double down on poo poo like this before and it's super frustrating working on a project that's fundamentally doing something that it shouldn't be doing.

Correction: it wasn't slow to switch OSes, article guy clocked it as only 6s to go from windows to linux.
But the whole reason they added it was as an "instant-on" alternative to avoid slow initial boot-up speeds for Windows, and it did nothing to help that -- the initial boot was about the same speed.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Volte posted:

My favourite Windows start menu search behaviour (which thankfully seems to be fixed in Win11) was typing "VLC" and the first highlighted result was "VLC media player - reset preferences and cache files" instead of the main application.

W10 still seems to use some kind of unpredictable/unstable search ranking function. If I type "Ch" the first result is "Google Chrome", but if I then continue and type "Chr" it replaces the first result with my "Google Chrome Guest mode" shortcut -- it replaced the original #1 match despite it still being an exact result.

Similarly, a search of "volum" pops up "Adjust Volume -- system settings" in the control panel, but "volume" brings up "Sound mixer options" instead. :confused:

RPATDO_LAMD fucked around with this message at 05:52 on Mar 30, 2023

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Toshimo posted:

You're the one who told us you just type random commands into you Unix prompt and hope they do something non-catastrophic. Which just lmao if that's the case.

are you aware of tab completion? there's a difference between "mash my keyboard randomly and hope something good happens" vs "type the first 3 letters of some niche rarely-used command I half-remember and then let my terminal list out the completion possibilities"

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Loezi posted:

DELETE CASCADE posted:

if you're writing python, and you use the keyword "class" writing code touching computer, you hosed up

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Hammerite posted:

motherfucker,



your login name is not necessarily the same as your publicly visible steam account name
and if like me you only used steam on one pc and had it set to auto sign in you might have not actually seen that login name for years

e: wait this is the coding horrors thread not the steam thread

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
Any info online on how to tweak some config value in the registry is always surrounded by multiple paragraphs of "this is dark magic and your computer is going to explode if you touch anything wrong make sure to save 7 backups first".

End users are absolutely terrified of the registry compared to config files.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
It looks pretty stupid for 1-argument constructors like that where you can just use "Fart fart = 42" but it can be nice to cut down repetition for multi-arg constructors where you actually do have to type out the constructor name

for example if I want to make a vector with 10 pre-initialized objects:
C++ code:
std::vector<MyAnnoyinglyLongCustomTemplateClass<Foo>> foos = std::vector<MyAnnoyinglyLongCustomTemplateClass<Foo>>(MyAnnoyinglyLongCustomTemplateClass<Foo>(someDefaultValue), 10);
// versus this which sucks a little bit less:
auto foos = std::vector<MyAnnoyinglyLongCustomTemplateClass<Foo>>(MyAnnoyinglyLongCustomTemplateClass<Foo>(someDefaultValue), 10);

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
is the horror that public posts on a social media website are visible on its public api?

surely even if they required that the api consumer have a "bsky invite code" during the closed beta period it would make no difference, that data is out there anyway. if someone wanted to scrape stuff they could finagle a code from somewhere

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Plorkyeran posted:

Doesn't Roblox skip the step of paying them actual money, though?

it pays them in "robux", which can technically be cashed for real money but only for around 1/4th the amount it costs to buy robux.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
i would really not recommend turning in transpiled or otherwise machine-generated code for a school assignment
assuming the professor is even the smallest bit competent they will have some level of human-beings-actually-looking-at-the-code (even if it's just TAs) beyond just automatic grading.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

ExcessBLarg! posted:

As the rest of the thread is kind of beating around, it's interesting to me that this course uses C++ as the language of instruction. Most schools switched to Java or C# some 20 years ago, because even back then C++ was a language with a lot of legacy and baggage, and the nuances of C++ aren't easy for a novice to decipher and, simultaneously, distract from the actual learning of data structures and algorithms.

Also, I don't think an autograder running on a correct, but inefficient program should result in a failing grade unless the student has access to the autograder ahead of the assignment due date (it wasn't clear to me if this was the case here), and even then I'm not sure it should do that. Like, a student inefficiency using an O(n) search where a O(1) lookup is warranted is a common mistake to the point that the autograder should be aware of it.

It's a data structures and algorithms course. Understanding the difference between a linear scan and a hashmap/etc lookup and when you'd use one over the other is precisely what they're being graded on. That's probably the best subject matter to have runtime-based tests for since if someone's time complexity is higher than it ought to be it's easy to blow it up.

Also how would you teach stuff like trees and linked lists in a 'friendly' language without pointers like java or python?

Ihmemies posted:

Actually no. ”does this make sense” or “what would be a good choice when implementing X” are very forbidden questions. “Why is this so slow”.. haha, they always say you have to figure it out yourself. If something literally doesn’t work they might give some advice, after a while.

Never got any answers from course personnel, I have tried. They’re all like “we have taught the theory, now it is your task to apply it in practice”. So if you did not understand something, too bad!

Peer review is feedback we have I give to other students after the project deadline has passed. That plus automated testers save course personnel’s time.

This part really sucks though. I understand not giving students the answers but they should point em to profiling tools or something

RPATDO_LAMD fucked around with this message at 03:21 on Dec 10, 2023

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
The syntax is a lot worse when it doesn't differentiate between reference and value types like that imo.
But C++ has the same sin with its own references.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
I took an elective "number theory and cryptography" course where the professor was in that same "I don't care about what language you use just get the math parts right" stance. We had to implement a bunch of things in software like various prime factorization algorithms, and eventually asymmetric key encryption.
However at my school it listed a CS course as a prerequisite. I feel like I was the only one there using Python (it has native arbitrary-precision integers! so nice for this.) while everyone else was struggling with some third party C++ BigInt library since the prereq class taught C++.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

ExcessBLarg! posted:

To refine my earlier point, I'm struggling to think of an example of needing 100+ "else if" blocks that couldn't be written in a better (whether stylistic or performant) way.

Which is to say that the limitation itself may be defensible.

you have some pretty weird standards if you think 100 if-elses is bad but 100 switch cases is suddenly good / "better"
it's all the same poo poo

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
what yall really need is some solid mathematical background for your IsEvens

Python code:
def isEven(x):
    return not isRelativelyCoprime(x, 2)
    
def isRelativelyCoprime(a, b):
    if b > a:
        a, b = b, a
    # if two integers a and b are coprime to each other, then
    # for all integers i and j,
    # b*i % a == b*j % a implies i % a == j % a.
    for i in range(0, a):
        for j in range(i + 1, a):
            if (i * b) % a == (j * b) % a:
                if i % a != j % a:
                    return False # found a counterxample!
    return True

it uses modulos, and it only takes quadratic time to run!

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Hammerite posted:

I was going to say that it should be ok because no initialization of variables was being skipped, but actually it potentially is if I understand correctly.

The initialization of i to 0 occurs in the for loop header and it ought to run because the state is initialized to "at start" - but having said that, all the properties are public, so the user could construct one of these, then change the state and then call resume() to get it to run without i being initialized? But you could fix that by just initializing i to 0 along with all the other members so I don't know why the author didn't just do that.

Even if the enum member was (say) made private so that you couldn't do that, it seems like it's asking a lot of the compiler to prove that i isn't accessed before it's initialized? You would think the compiler would warn about it.

I guess in C++ both the "switch" and "for loop" language features translate pretty directly to labels and gotos, and it's clear how you convert that code into labels and gotos and it shouldn't cause any problems, so other than the uninitialized variable thing, I don't know how plausible it really is that it would be undefined.

It's a while since I touched C++.


"this is bad because if you gently caress with internal object state you can put it in an invalid state" is a very "you're holding it wrong" kind of problem to have

the real problem is that it's using the switch as a fancy goto which is just fucky and unintuitive to read.
you could easily refactor this to use separate start(), loop(), done() functions instead of jumping into the middle of a block of shared code.

Adbot
ADBOT LOVES YOU

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
Cmake is designed to find dependencies by "magic" through functions like find_package, which basically end up looking for a hand rolled script for each package or else searching in a few standard folders like /usr/lib etc
Getting that poo poo to work on windows which has no standard folder structure anywhere for libs, includes, etc is a pain in the rear end, and because of all the "magic" involved specifying the folder locations explicitly ends up being more verbose and much less obvious than it would've been with a dumb non-magical build system like a plain makefile. And yes the documentation is really poo poo for this with a lot of super general detail on how the various functions work and no simple hello-world examples for "holy poo poo I just wanna link to a library it's RIGHT THERE please just show me three lines of code/config that will do this"

it seems like a pretty good system as long as you (a) never touch windows and (b) never have to actually write the drat cmake files yourself

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