https://simonwillison.net/atom/everything 10月22日 14:29
SLOCCount WebAssembly项目:代码量统计工具的Web化尝试
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文讲述了作者将经典的SLOCCount代码行数统计工具移植到WebAssembly的尝试过程。起初,作者希望利用WebPerl在浏览器中运行SLOCCount,并指导AI完成UI和GitHub仓库集成。然而,AI尝试失败后,作者转而指导AI使用Emscripten将SLOCCount的C语言部分编译为WebAssembly,最终成功构建了一个包含代码粘贴、GitHub仓库加载和Zip文件分析功能的Web应用。尽管成本估算价值有限,但该项目展示了LLM在复杂跨平台开发中的潜力。

🚀 **项目起源与目标:** 作者受到经典SLOCCount工具的启发,旨在将其移植到WebAssembly,以便在浏览器中运行代码行数统计和开发成本估算功能,并利用LLM辅助开发。

💡 **技术挑战与演进:** 项目初期尝试使用WebPerl在浏览器中运行Perl版本的SLOCCount,但AI尝试失败。随后,作者引导AI使用Emscripten将SLOCCount的C语言组件编译为WebAssembly,并整合到项目中,解决了跨语言的兼容性问题。

🔧 **功能实现与用户体验:** 最终实现的Web应用提供了三种代码输入方式:直接粘贴代码、通过GitHub仓库URL加载,或上传Zip文件。应用界面友好,支持移动端访问,并加入了可调整的成本估算参数,但附带了明确的提示,说明其估算值的局限性。

🤖 **AI辅助开发的经验:** 作者分享了与AI协作的详细过程,包括指导AI解决技术难题、调整代码实现,以及AI在理解项目需求和技术细节上的表现,强调了在复杂开发中与AI有效沟通的重要性。

SLOCCount in WebAssembly. This project/side-quest got a little bit out of hand.

I remembered an old tool called SLOCCount which could count lines of code and produce an estimate for how much they would cost to develop. I thought it would be fun to play around with it again, especially given how cheap it is to generate code using LLMs these days.

Here's the homepage for SLOCCount by David A. Wheeler. It dates back to 2001!

I figured it might be fun to try and get it running on the web. Surely someone had compiled Perl to WebAssembly...?

WebPerl by Hauke Dämpfling is exactly that, even adding a neat <script type="text/perl"> tag.

I told Claude Code for web on my iPhone to figure it out and build something, giving it some hints from my initial research:

Build sloccount.html - a mobile friendly UI for running the Perl sloccount tool against pasted code or against a GitHub repository that is provided in a form field

It works using the webperl webassembly build of Perl, plus it loads Perl code from this exact commit of this GitHub repository https://github.com/licquia/sloccount/tree/7220ff627334a8f646617fe0fa542d401fb5287e - I guess via the GitHub API, maybe using the https://github.com/licquia/sloccount/archive/7220ff627334a8f646617fe0fa542d401fb5287e.zip URL if that works via CORS

Test it with playwright Python - don’t edit any file other than sloccount.html and a tests/test_sloccount.py file

Since I was working on my phone I didn't review the results at all. It seemed to work so I deployed it to static hosting... and then when I went to look at it properly later on found that Claude had given up, cheated and reimplemented it in JavaScript instead!

So I switched to Claude Code on my laptop where I have more control and coached Claude through implementing the project for real. This took way longer than the project deserved - probably a solid hour of my active time, spread out across the morning.

I've shared some of the transcripts - one, two, and three - as terminal sessions rendered to HTML using my rtf-to-html tool.

At one point I realized that the original SLOCCount project wasn't even entirely Perl as I had assumed, it included several C utilities! So I had Claude Code figure out how to compile those to WebAssembly (it used Emscripten) and incorporate those into the project (with notes on what it did.)

The end result is actually pretty cool. It's a web UI with three tabs - one for pasting in code, a second for loading code from a GitHub repository and a third that lets you open a Zip file full of code that you want to analyze. Here's an animated demo:

The cost estimates it produces are of very little value. By default it uses the original method from 2001. You can also twiddle the factors - bumping up the expected US software engineer's annual salary from its 2000 estimate of $56,286 is a good start!

I had ChatGPT take a guess at what those figures should be for today and included those in the tool, with a very prominent warning not to trust them in the slightest.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

SLOCCount WebAssembly JavaScript Perl Emscripten AI LLM 代码统计 开发成本估算
相关文章