Programming a Hacker News Clone with AI

By Joel Dare - Written September 9, 2024

Further Develop the Idea

First, I use a prompt to ask it to further develop the idea.

Develop below paragraph:
I want a hacker news clone. It should use the neat css framework for html/css. It should list highest ranking articles in order of popularity on the home page. Users can vote up (but not down). There should be some type of time based decay. New users should be created with just username and password. Users should be able to add a post or a comment and comments should be threaded. Comments on their own web page. It should use a SQLite database. Backend should be written in go and use a rest api.

Here’s the idea it returned.

Here’s a detailed specification for a Hacker News clone:

Frontend

Time-based Decay

User Management

Comments

Backend

API Endpoints

This specification should provide a solid foundation for building a Hacker News clone using the Neat CSS framework, Go backend, and SQLite database.

Manually Edit the Idea

Next I tweak the idea that it generated in subtle ways that I think are important and to add detail.

Break the Project Down

I ask it to break the project down into steps. I include the modified developed idea from above plus my question. I do this in a new conversation.

{Developed Idea}

Break this project down into individual steps that need to be completed.

It responded with the following steps.

Here’s a breakdown of the project into individual steps:

Step 1: Set up the frontend

Step 2: Implement user authentication

Step 3: Set up time-based decay

Step 4: Create API endpoints for articles

Step 5: Implement user comments

Step 6: Implement threaded comments

Step 7: Set up API endpoints for comments

Step 8: Implement user authentication for API endpoints

Step 9: Set up API endpoints for article creation and scoring

Step 10: Test and iterate

Ask it to Complete a Step

I asked it to do the first step, which it did, but it didn’t follow the spec, or at least, not the way I wanted it to. Instead it just wrote a basic HTML file. No Neat CSS was included. So, I installed Neat CSS with it’s default instructions then copied the neat.html file over top of index.html and removed the body. Finally, I copied and pasted a few minor details from it’s answer on top of that, such as including a js file and the empty article list.

I asked it to further develop the article list with some examples.

Lets add a dozen example article titles and url’s also add an example author name, score, and posted date. All to the articles section.

Ask it to Refine

It made each link too complicated and added a bunch of extra data. Rather than fix it all myself, I asked it to fix the problem.

Information is duplicated in the link such as the authors name. Lets reduce the link to just the title (the part in quotes) and then remove the title= value from each.

It came up with garbage again, here’s what it returned.

<li>
    <a href="#" title="Example Article 1">"The Future of Space Travel"</a>
    <span class="author">John Doe</span>
    <span class="score">Score: 100, Posted: 2023-02-20</span>
</li>

Things I don’t like about this return:

I ended up rewriting this manually into this format. Just personal preference, really.

<main>
    <section class="articles">
        <a href="url">The Future of Space Travel</a>
        <div class="info">100 points by <a href="#">johndoe</a> 4 hours ago | <a href="#">upvote</a> | <a href="#">comments</a></div>
    </section>
</main>

I ignored most of what it returned through the rest of this conversation and just did it the way I wanted it. Except I let it write this part for me.

How do I add a margin-top to every articles section except the first?

I asked it a few more questions as I refined the html and css to my liking.

I coudn’t remember the exact css formatting for this, so I just asked it.

How do I add a margin to each article but not the first article?

I couldn’t think of the word “opacity” so I just asked it.

How do I add transparency to a css item?

At this point I finished for the day. I’m not two hours in and I only really have the html page written with dummy info, the database created, and some other minor scaffolding.

I do like having the todo list. Going back to that list, at the end of my session, I notice that I’ve completed the entire first section, not just the first instruction. Next I’ll be on to pulling the data from the database.

Leave a Comment
(formrobin.com)

JoelDare.com © Dare Companies Dotcom LLC

Terms - Privacy