ChatGPT - How Long Till They Realize I’m a Robot?

Image
I tried it first on December 2nd... ...and slowly the meaning of it started to sink in. It's January 1st and as the new year begins, my future has never felt so hazy. It helps me write code. At my new company I'm writing golang, which is new for me, and one day on a whim I think "hmmm maybe ChatGPT will give me some ideas about the library I need to use." Lo-and-behold it knew the library. It wrote example code. It explained each section in just enough detail. I'm excited....It assists my users. I got a question about Dockerfiles in my teams oncall channel. "Hmmm I don't know the answer to this either"....ChatGPT did. It knew the commands to run. It knew details of how it worked. It explained it better and faster than I could have. Now I'm nervous....It writes my code for me. Now I'm hearing how great Github Copilot is - and it's built by OpenAI too...ok I guess I should give it a shot. I install it, and within minutes it'

Flyweight Design Pattern

So you have a group of objects that can be reused, but each time you use one you have to create it first. The problem is that instantiating these types of objects is expensive, and you don't want to instantiate the same kind every time you need it. Enter Flyweight design pattern. With this pattern, the trick is to create a new object only when you've never created that same type of object before - if you HAVE created it before, then simply look it up and use the one that's already instantiated. Here's some code:

public class Flyweight
{
    public static Dictionary _Table = new Dictionary();

    public ISomething GetSomething(int key)
    {
        ISomething something;
        if(_Table.TryGetValue(key, ref something))
        {
            return something;
        }
        else
        {
            something = new Something(key);
            _Table.Add(key, something);
            return something;
        }
    }
}

What this code does is ensure that the only time an object of type ISomething is instantiated is when there's a type requested that hasn't been requested before. Otherwise it'll return the one that was requested before. The GOOD: saves clock cycles by instantiating each type only once. The potentially BAD: uses more memory than creating new instances on the fly. Cheers.

Comments

Popular posts from this blog

ChatGPT - How Long Till They Realize I’m a Robot?

Architectural Characteristics - Transcending Requirements

The Terms that Blind Us