TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: What was your “eureka” moment while programming?

3 点作者 minionslave超过 8 年前
My Eureka moment was when I figured out what interfaces were for.<p>I never understood the difference between interfaces and abstract classes. I asked on online forums and stackoverflow the typical answer I got was: &quot;An interface is a contract that you define... A class has to implement the methods defined in the interface for it to work.&quot;<p>&quot;Why do I need to use a contract if I can can simply implement the call the methods directly? Why do I need that middle man&quot;. I was working on a small web api project with Nancy, MySQL lite was used initially, but, I wanted to use a database like MySQL or PostgreSQL. The small project I was working on to learn Nancy needed refactoring. So, I asked myself &quot;What if I could swap database at will&quot;. That when all the concept of interfaces came together.<p>I could simply use an interface as a mediator, which mean defining methods inside an interface, as long as the code calling the database implements these methods, things will work fine.

1 comment

hoodoof超过 8 年前
Understanding how to pass functions.<p>For me this was more important than grasping object oriented programming.<p>The second deep insight was that programming is less about language syntax and mostly an exercise in manipulating data into and out of common data structures such as arrays and hashes.
评论 #12485534 未加载