我提议开发一种新的编程语言,名为 CPC。

2作者: tom_gi4 个月前
我正在为理解和解决谷歌的LeetCode问题而开发一种编程语言。它被称为可编译伪代码,简称CPC。诚然,这个名字是故意自相矛盾的;目标是编写足够严谨、可以编译的伪代码。这个想法最初是在2023年的一次谷歌面试后产生的。面试官告诉我,“伪代码是可以的。”老实说,当时我脑子里想着用Python对图进行深度优先搜索来检测循环,所以并没有认真考虑伪代码。这是一个错误,因为它阻碍了与面试官的交流,也让我失了分。因此,我提出了CPC。 其目的是让谷歌面试官不仅能够理解你的解决方案,还能看到你精通算法思维。 这个想法很简单。一切都是列表。在CPC中,列表的定义是这样的,即使是一个神童也能轻松理解:列表是按顺序排列的项目的集合,其中每个项目都有一个位置。 将LeetCode中出现的所有数据结构抽象成列表的最常见形式。换句话说,哈希表是一个列表,其中每个项目都有一个名称和值。对每个数据结构都重复这个过程,以便在CPC中使用尽可能少的术语。 然后,CPC的语法就是用简单的英语描述伪代码。该代码支持“摇摆”。换句话说,你可以用多种方式用简单的英语来描述一个解决方案。 有什么想法吗?如果这里有支持者,我建议我们作为一个社区,开始推导出CPC解决常见LeetCode问题的方法。一旦我们达到500个问题的里程碑,我们就可以将CPC作为一种官方的可编译语言发布。
查看原文
I&#x27;m starting my own programming language for understanding and solving leetcode problems at Google. It is called compilable pseudocode, or CPC. True, the name is intentionally paradoxical; the goal is pseudocode rigorous enough to compile. The inspiration first came to me some time after a Google interview in 2023. The interviewer told me, &quot;pseudocode is fine.&quot; Honestly, I had depth first search on a graph to detect cycles in Python on my mind, so I did not seriously pursue pseudocode. That was a mistake, because it shut down conversation with the interviewer, and cost me points. Hence, I propose CPC.<p>The purpose is that Google interviewers will not only comprehend your solution, they will see you are fluent in algorithmic thinking.<p>The idea is simple. Everything is a list. In CPC, a list is defined so that a child - albeit a prodigy - could easily understand: a list is a collection of items, in order, where each item has a position.<p>Take all the data structures that appear in leetcode, and abstract them away to their most common denominators in terms of lists. In other words, a hash table is a list where each item has a name and a value. Repeat this for every data structure so that there is as little jargon as possible in CPC.<p>Then the syntax for CPC is just the plain english describing the pseudocode. The code supports “wobble”. In other words, you can use plain english to describe a solution in more than one way.<p>Any thoughts? If there are supporters here, I propose we as a community proceed to derive CPC solutions to popular leetcode problems. Once we hit the 500 problem mark, we can publish CPC as an official compilable language.