Please help contribute to the Reddit categorization project here

    BecausIts2016

    + friends - friends
    1,921 link karma
    36,030 comment karma
    send message redditor for

    [–] Convert.ToInt32() or Int32.TryParse() BecausIts2016 1 points ago * (lasted edited 24 days ago) in csharp

    Your code example, catching the inner exception, is probably technically best practice. If you capture the input string you can easily discern what the parsing failure is though, you're not really throwing it away. If you really needed to know the specific reason (null, format, overflow), simple string analysis is certainly cheaper than allowing parse to throw, catching, wrapping, and rethrowing. Edit; over 50% faster in the test I wrote.

    I guess it's just personal preference and habit. I just find the TryParse method with a custom exception cleaner and faster for the same functionality. It's also a clear winner for me on client side, where you typically don't want to throw at all on invalid input.

    [–] Calculating memory allocation and checking feasibility. BecausIts2016 1 points ago * (lasted edited 24 days ago) in csharp

    First question is, am I missing anything in my calculations?

    A bit, yes.

    Objects have a header that contains the syncblock and typehandle. That's 8 to 16 bytes of overhead depending on 32 or 64 bit words. Additionally, your fields, a boolean (1 byte) and a byte (based on your 8 bits mention) don't naturally align with word boundaries. The compiler will pad the size of your Beat object to 12 or 24 bytes so it aligns with address boundaries. Furthermore, at the very least one pointer needs to exist for the object not to get garbage collected. That's another 4 or 8 bytes and will be held in your arrays. Arrays have a similar header, but are larger than regular objects. For simplicity, and because it's largely negligible (your jagged array holding 7 arrays = 8 arrays = ~100 bytes of overhead with 32 bit words), we'll ignore this.

    Second question is if this is a feasible thing to load at the start of a level and how would I go about estimating the speed required to load it.

    I assume you're loading it into your arrays from some type of storage? This has a lot less to do with the in memory layout of your object and arrays than it does with your storage, file format and size, hard drive speed, etc. There can also be large variance impacted by things like: other programs touching the disk, disk fragmentation, etc. This makes it extremely difficult to accurately predict beforehand. If your files are small and your load routine processing is minimal, you shouldn't really worry at all.

    [–] Convert.ToInt32() or Int32.TryParse() BecausIts2016 1 points ago in csharp

    It's also precisely what TryParse tells me, with the added benefit that I can propagate it to my handler as a single exception type with the relevant context information attached.

    [–] Convert.ToInt32() or Int32.TryParse() BecausIts2016 0 points ago in csharp

    Yeah, you could. But generally I don't care if it's an overflow, formatting or argument null. That's easy to discern from capturing the string value. What matters is that we've received an invalid input. You can logically group it into a single exception and capture additional context.

    [–] Convert.ToInt32() or Int32.TryParse() BecausIts2016 -1 points ago in csharp

    The advantage of Convert.ToInt32() is that it'll throw an exception for you, but that gets defeated (imo) by the fact it gracefully eats null strings and returns 0 (which might also be a valid expected value).

    I always use Int32.TryParse(), typically like this.

    if(!Int32.TryParse(str, out i))
       //throw
    

    [–] I just can't understand how to work with arrays on a Windows Form app BecausIts2016 3 points ago * (lasted edited 24 days ago) in csharp

    A few pointers.

    • Start by thinking about the steps of your problem + solution logically, independent of any code. The code comes afterward and is simply the expression of those logical steps in computer language.

    • Judging by your comment, users will be inputting the numbers one-by-one individually. You will need to output those numbers once 5 have been entered?

    • Logically we'll need: 1) a counter to track how many numbers have been input, 2) a place to store numbers that have been input, and 3) to check when 5 have been entered.

    Computer language complicates this a little bit, and we'll end up with logical steps exceeding 3. Logically, your button click handler should be doing this.

    1) check if input string is null or empty.

    2) check if input string is numeric.

    3) parse input string into Int32 format.

    4) store value into array at counter position.

    5) increment counter (+ modulus 5 operator).

    6) check if counter equals zero, if so, output your array by formatting the numbers to label.Text.

    If you have any questions, feel free to ask.

    [–] Which language features or behaviours do you forget how it works every now and then? BecausIts2016 2 points ago * (lasted edited 25 days ago) in csharp

    I did something similar a while back, almost 2 years ago now. If I recall correctly, if you want full functionality across all primitives, you'll need to PInvoke (or C++/CLI wrapper) some of the Interlocked functions that C# Interlocked doesn't expose.

    Another fun project with Interlocked is creating lock free single reader single writer collections (queue, stack, etc). The performance gains are pretty substantial over .NET's multiple reader multiple writer concurrent collections.

    [–] Confusion with OOP BecausIts2016 3 points ago * (lasted edited a month ago) in csharp

    Static methods belong to the Type and are therefore called through the Type.

    MyClass.StaticMethod();
    

    Instance methods also technically belong to the Type, but it's easier to logically think of them as belonging to the specific instance. They are invoked on an instance of the Type.

    myClassInstance.InstanceMethod();
    

    The reason you might be confused in #3 is probably because of scope. Static methods are independent of instances and have a global scope. Therefore they are easily invokable but no implicit instance exists like with instance methods. There is, however, nothing preventing static methods from calling instance methods. You just need an explicit reference to an object instance in scope. Take for example:

    static int Sum(params MyClass[] args)
    {
       int total = 0;
       foreach(MyClass c in args)
          total += c.GetSize(); //call instance method
      return total;
    }
    

    As for your last point:

    A derived class has access to the public, protected, internal, and protected internal members of a base class. Even though a derived class inherits the private members of a base class, it cannot access those members. However, all those private members are still present in the derived class and can do the same work they would do in the base class itself. For example, suppose that a protected base class method accesses a private field. That field has to be present in the derived class in order for the inherited base class method to work properly.

    Again, technically, private members are inherited and exist in the derived class. But you won't be able to access them in the derived class like you would be able to in the base class. C# has the protected access modifier for this reason.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 1 points ago * (lasted edited a month ago) in news

    Honestly, I'm not even sure what we're debating anymore. You've steered the discussion from: It's not funny. I explained why I find it funny. To restraint in comedy, which would just produce drab corporate monologues. All the way to employment and professionalism, something I'm not even discussing.

    Edit;

    P.S., robbery pranks are actually some of the more successful ones. Given, it's not usually conducted inside the bank due the high potential of eating lead.

    [–] Florence leaves 7 dead, nearly 1 million without power. BecausIts2016 0 points ago in news

    That's fortunate, the last time I heard it mentioned in the news they said it would be a weak cat 4 or strong cat 3 at landfall.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 5 points ago in news

    I guess you've never seen Just For Laugh Gags, or the variety of Youtube channels that rose to prominence on the back of their street pranks. I guess the difference is the target of the gag wasn't random pedestrians, but the fourth estate, which is uniquely situated to raise the gag into national prominence and cultural ethos.

    [–] Florence leaves 7 dead, nearly 1 million without power. BecausIts2016 147 points ago in news

    Loss of life is always tragic, but only 7 dead so far sounds like a result on the better end of the spectrum.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 6 points ago in news

    If I'm overreacting, why are you such a staunch defender of this?Jokes can be in bad taste, like this one. It's bad taste, people think you are being racist.

    Defender of what? Offensive comedy? Most of my favorite comedians were doing offensive stand up routines in the 90s and early 2000s. Much more offensive than this OK hand sign gag (Jewish gas chamber jokes, Chris Rock / Dave Chappelle with their racial comedy, etc). Sanitized, punches held comedy is largely boring. I prefer no holds barred.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 6 points ago in news

    It's more like: think of the most absurd shit you can, take it to national prominence, convince a broad swathe of people, who then become hysterical at the initial absurdity. In that sense, it's a lot like Reefer Madness of the 21st century. I don't know about you, but I think most retrospective observers find Reefer Madness packed full of comedic value. Absurd claims, taken to national prominence, that produced hysteria. The comedic value is multifaceted.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 51 points ago in news

    I'm an international participant, don't really know anything about Stephen Miller. It would probably be more productive if you cite the evidence for your own claim.

    But the original context we're dealing in is that the OK hand sign is a white supremacist signal. Given that Jews are practically universally rejected and despised in those circles, it would be odd for a mixed-race Jew to claim membership.

    If we deviate from Occam's Razor, we're charting in Dave Chappelle black KKK territory, an exaggerated comedic skit. How many black people do you see sporting the hoods and robes in real life? I tend to lean toward what is most likely in my assumptions.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 59 points ago in news

    I mean, personally, I think anybody equating the flag of a genocidal regime and an innocuous hand symbol probably needs some fresh air, especially since this traces its origins to an expressed intent to troll. Wikipedia sums it up better than I can:

    In February of 2017, users on the anonymous imageboard /pol/ of 4chan set out on a prank to convince mainstream media outlets that the OK hand gesture had been hijacked for use by white supremacists to signal one another publicly. Most of these media outlets have since recanted their statements, citing the official response from the ADL. The ADL has confirmed that the OK gesture is not a white supremacist hand sign.

    The ADL piece is titled, shocker, "How the “OK” Symbol Became a Popular Trolling Gesture."

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 68 points ago in news

    I remember a high profile incident recently at the Kavanaugh hearing. The perpetrator was Jewish/Mexican I believe. Twitter exploded. Other than that, we seem to only get asinine stories like this with no follow up.

    [–] Ohio police officer gets 43 years for on-duty sex assaults BecausIts2016 2 points ago in news

    It elevates your threat level. That gets compounded exponentially if you're acting erratic. The database notes that 1/4th of the cases involved some type of mental illness, and over 1/3rd involved fleeing suspects. Just surface level information indicates a high level of erratic behavior in the sample. That information is lacking though because it doesn't encompass instances like people advancing on police while brandishing a weapon, or reaching for a weapon. The database is comprehensive but not quite that comprehensive. Maybe once body cameras are more widespread. The database does contain some of those specific cases with body cameras available, so somebody with the time could delve into their database with more thoroughness.

    [–] Coast Guard Member Flashes White Power Hand Signal On TV BecausIts2016 211 points ago in news

    This OK hand sign trolling has to be some of the most hilarious shit of 2018.

    [–] Bronx teacher who performed oral sex on 14-year-old gets 10 years probation, avoids jail, keeps teaching certificate BecausIts2016 -32 points ago in news

    She's a sex offender no doubt, and there's clearly a double standard. But it's rooted in something logical. I bet most of the men complaining in this thread about the aforementioned would have been joyous to have this babe slobber on their knob if they were her student. I doubt it would have negatively impacted them in any way, probably the opposite. Quite predictably this was discovered because the kid was bragging to his friends.

    Source: remember being 14 and what would happen whenever we had a hot teaching assistant or teacher.

    [–] Ohio police officer gets 43 years for on-duty sex assaults BecausIts2016 4 points ago in news

    You realize the vast majority of people shot by police ether don't have guns or never intended to use a gun.

    Not according to the WashingtonPost police shooting database. The large majority are armed.

    2017 statistics. 987 fatal police shootings. Gun: 579, Knife: 156, Toy weapon: 26, Other: 132, Unarmed: 68, Unknown: 26.

    [–] U.S. customs to bar Canadians, who work, invest or partake in the cannibis industry BecausIts2016 6 points ago in news

    I'm not entirely sure what he means by the "civilized world," and "lighten up" presumably includes decriminalization as well, and not just outright legalization. Wikipedia has a map for the legality of cannabis across the world.

    Europe has a mix of decriminalization and criminalization, with illegality appearing to be the most prominent. Asia appears to have criminalization exclusively. Latin America is dominated by decriminalization, with small pockets of criminalization.

    Of course, Wikipedia isn't the best source, but it's decent for a cursory look. Canada isn't marked as "legalized" yet because their table makes note that it takes effect in October. Weed is legalized or decriminalized in about half the U.S. at the State level according to this map.

    [–] California to NRA: Stop selling insurance for gun injuries BecausIts2016 4 points ago in news

    Street cred...and to emphasize the obvious, that it would be an indirect ban.

    [–] California to NRA: Stop selling insurance for gun injuries BecausIts2016 106 points ago * (lasted edited a month ago) in news

    Didn't your Supreme Court already rule that attempting these types of indirect bans is unconstitutional? I think the specific case had something to do with ammunition.

    edit; grammar