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
leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Volte posted:

Forget the word "null", it's distorting your viewpoint. Option is effectively a list that can have either zero or one element in it, and as a result you can basically use all the nice patterns that you can use with lists (and a few others that come from the zero-or-one property too). Null specifically means an invalid pointer, and it is sometimes (mis)used to represent the "empty list" case, but None and null aren't the same thing.

Null is the absence of value. The concept isn't unique to pointers.

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Polio Vax Scene posted:

my problems may be undefined or absent depending on the language i am using

My problems are severe but not representable.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

ExcessBLarg! posted:

I'm struggling to think of a good example of having 100+ "else if" blocks even for generated code. Surely it could be converted to some kind of dispatch mechanism, or at least convert the conditional tests into a tree form.

I want to write my code generator in 5 minutes, and generating additional elif blocks is easy.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

NihilCredo posted:

car-cons-ization was right there

car-cons-inogens

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

shame on an IGA posted:

TIL about python prepopulating integer objects for every value between -5 and 256 every time you run a program

there was no other way for them to increase performance

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

GABA ghoul posted:

Htbh, but I would not approve this in a pull request because it clearly doesn't work if you pass a 0(which is even). AI still has a long way to go before it can replace a real developer

or any negative numbers, despite signed input

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

GABA ghoul posted:

I think there is a very clever solution for this that could save a lot of work

code:

if (number < 0)
 number = int.Parse(number.ToString().Replace('-', ''))

theres code like this in my current project and i dont have enough pull to get the person who wrote it on PIP

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

GABA ghoul posted:

:love:

I love this so much, especially because it doesn't even work if you execute it on a German Windows

So here is the correct version that is actually safe to deploy internationally

code:


string decimalSeparator = Directory.Exists("C:\\Programme") ? "," : ".";

is_odd = (number / 2).ToString().Contains(decimalSeparator);

fail PR. use "." and the invariant cultureinfo

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

GABA ghoul posted:

This good solid code, but personally I would go with a more modern functional programming approach


Python code:


class Monad(Enum):
    NO = 1
    YES = 2
    MAYBE = 3

def is_even(x):
    return Monad.MAYBE


kleene logic leads to kleene code

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

ultrafilter posted:

It'd be even more efficient to move the precomputation to compile time.

use a generator expression so you only precompute values you might use

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Bruegels Fuckbooks posted:

That's actually a great idea! Here's the improved version:

code:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System.Text;

[Generator]
public class EvenNumberGenerator : ISourceGenerator
{
    public void Initialize(GeneratorInitializationContext context)
    {
    }

    public void Execute(GeneratorExecutionContext context)
    {
        var source = GenerateEvenNumbersCode();
        context.AddSource("EvenNumbers.g.cs", SourceText.From(source, Encoding.UTF8));
    }

    private string GenerateEvenNumbersCode()
    {
        var sb = new StringBuilder();
        sb.AppendLine("using System.Collections.Generic;");
        sb.AppendLine();
        sb.AppendLine("public static class EvenNumbers");
        sb.AppendLine("{");
        sb.AppendLine("    public static readonly HashSet<int> Numbers = new HashSet<int>");
        sb.AppendLine("    {");

        for (int i = 0; i <= int.MaxValue; i += 2)
        {
            sb.AppendLine($"        {i},");
        }

        sb.AppendLine("    };");
        sb.AppendLine("}");

        return sb.ToString();
    }
}

:yeah:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

csammis posted:

What is a database but coding horrors made transactional

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Soricidus posted:

The problem with it is that having a case statement in the middle of a loop is the kind of thing that might plausibly be undefined behavior or a compiler-specific extension. It’s obvious what the code intends to do, but it’s not a common idiom, so unless you’re familiar with the trick, it’s not obvious whether it will actually do that reliably, even if you run it and it seems to work on your machine.

That’s why it’s bad code.

what.

duff's device is a little silly, but it's not against the spec

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Zopotantor posted:

This is not really Duff's device though; it’s an implementation of a state machine or coroutine. In Duff's device the loop actually has a function, but here it would not really be necessary if the author had properly initialised "i" in the constructor.

efb

case statements in a loop have no issues

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Bruegels Fuckbooks posted:

its almost impossible to avoid getting sued for something if you work as a software developer long enough and release enough products - you can do all the patent search and perform all the rituals you want to try to ensure that you don't get sued and still end up with a lawsuit because someone has the software patent on an arrow that faces to the right indicating that a submenu is present on a context menu and your patent search should've picked up on that fact.

better to have a policy of not searching patents. avoids 3x damages

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