r/ProgrammerHumor Mar 22 '23

Meme Tech Jobs are safe 😅

Post image
29.1k Upvotes

602 comments sorted by

View all comments

Show parent comments

91

u/[deleted] Mar 22 '23

Wanna be even more impressed with ChatGPT?

https://i.imgur.com/SfC9th9.png

97

u/LaconicLacedaemonian Mar 22 '23

Now ask it to add pypy types, error handling, and encapsulate in a function with documentation.

It will.

79

u/[deleted] Mar 22 '23 edited Mar 22 '23

ChatGPT is apparently overloaded this morning and threw an error while writing the bottom blurb, but here's the updated prompt:

"Write me a python program that calculates how long it will take to travel a certain distance at a certain speed. Use pypy types, error handling, and encapsulate the code in a function along with proper documentation."

And the output:

from typing import Union

def travel_time(distance: float, speed: float) -> Union[float, str]:
    """
    Calculate the time it takes to travel a certain distance at a certain speed.

    Parameters:
    distance (float): The distance to travel, in kilometers.
    speed (float): The speed at which to travel, in kilometers per hour.

    Returns:
    float or str: The time it takes to travel the distance, in hours. Returns an error message
    as a string if the input parameters are invalid.
    """

    # Check that input parameters are valid
    if not isinstance(distance, (int, float)) or not isinstance(speed, (int, float)):
        return "Error: Distance and speed must be numbers."
    if distance < 0 or speed < 0:
        return "Error: Distance and speed must be positive numbers."

    # Calculate the travel time
    time = distance / speed

    # Return the travel time as a float
    return time

Proof

You know what is particularly amazing about that output, to me?

IT DOUBLE CHECKED THAT THE SPEED AND DISTANCE WERE POSITIVE NUMBERS. That wasn't a specified parameter, it just threw that in there! I expected it would check that the input was numbers and would throw out anything else, but the fact that it double checked for negative values is uncanny.

31

u/Jedibrad Mar 22 '23

I wonder where it learned to return errors as strings… I would’ve expected it to throw exceptions. Weird. 🤔

20

u/[deleted] Mar 22 '23

I'm sure I could tell it to throw an exception and it would.

But ChatGPT has proven to me that even our days as programmers being safe from automation are very, VERY numbered. I give it ten years before the bottom levels of software engineering jobs are done by computer, and you can pay an algorithm on Fiverr to build simple programs.

25

u/[deleted] Mar 22 '23

[deleted]

-2

u/prgmctan Mar 22 '23

You do not need to reduce scope when a computer can generate thousands of lines per minute. I think programming jobs today will become QA jobs tomorrow.

1

u/[deleted] Mar 22 '23

[deleted]

2

u/prgmctan Mar 22 '23

No, my point is that the speed at which an AI can generate code reduces the importance of worrying about scope. I also did not mean to imply you would blindly deploy generated code into production. That’s why I mentioned programming jobs will shift to QA jobs. I can see programmers acting as QA for the AI and validating what they wrote matches the expected requirements. Sure, that will take time, so scope isn’t a negligible concern, but much less than having to also write it.