Quick post on AI codingAuthor: Dave Date: 01.19.26 - 1:07pm I am going to do a quick informal post on AI coding. So to give it a shot, I wanted to try a rather involved project. My personal needs had me wanting a custom-built JavaScript engine from scratch, and a new Scintilla wrapper OCX control. Both would be done in VB6. After playing with several AIs, I settled on Claude.AI as my favorite. Both projects were quite involved and came out very well:
https://github.com/dzzie/js4vb I will mostly talk about the JS engine since it’s the bigger project and more complex.
To start, I have been a VB6 developer for 20+ years. It’s still my main language.
If you're curious how we got here and why I bothered to build a custom engine from scratch... it’s because I’ve been hitting a wall for over two decades. This project is the culmination of years of trying to "bolt on" scripting to VB6 with varying degrees of success.
1. The MS Script Control (1998):
The starting point for everyone. It works, but it’s stuck in the ES3 spec (ancient syntax) and lacks any real debugging support. I wanted more control.
2. IActiveScript & Citrus:
I tried to use the raw
IActiveScript debugger interfaces in VB6. It was brutal and never fully worked right. Ken Foust had his Citrus debugger in C++, but at the time, that level of C++ was beyond me.
3.Script Basic & First Debugger Success (2014):
I experimented with the Script Basic engine. It had a debugger interface that let me play relatively easily. I tried bolting on COM integration, but my additions were rough and crashy — script errors could easily be fatal to the host. This was however my first win getting C-to-VB in-process callbacks for script debugger control.
4. Duktape:
Next was Duktape, a nice, small C engine. I wrapped it into an OCX and used it for years. It was stable, but my COM integration was still a bit clunky (requiring custom JS classes and resolvers). The biggest dealbreaker was that JS has no true 64 bit number support. For the tasks that I do, JS standard 53 bit numbers was a head ache.
5. Py4vb:
Next I tested Python integration with VB6. Thanks to Mark Hammond’s pywin32, COM access was seamless. Python however requires 30MB+ of run times, has messy internals, and embedding is clearly an after thought for the language. I had to hack the main execution loop just to add an abort mechanism.
After 25 years, I knew exactly what I wanted:
Problem, I just didn't have the 1,000+ hours required to hand-code it. Now with new tech, AI finally gave me the power to execute on a vision I've had since the late 90s. First, I started by creating a JS AST parser. This is the foundation for a script interpreter and is a whole project all on its own. We built this up iteratively. I used jquery.js as my test suite and we kept working until it could be parsed successfully. We designed hundreds of tests and added tons of debugging output as we went. We finally got it stable. I then asked about corner cases and other common gotchas and we worked through these. Turns out this is a perfect target for AI:
Once the AST parser was solid, we then got to work on
the interpreter and we started incrementally adding features.
We then started adding some fancy features like true 64-bit numbers (in a host language that doesn’t support them!) and seamless COM support. We even had to write some C DLLs for things that I would not attempt in VB6 itself.
Check out the project readme. The features are actually pretty impressive! This was about 50 hrs of coding, which is simply not a possible timeline in any other way regardless of team size, budget, or expertise. This level of productivity is only possible through AI. This should have taken a team of 4 a year solid. So what did I learn?
Ok, so now on to some practical concerns. To code this JS engine I easily burned through 18 different contexts. Each context has a length limit. As it gets “tired” or “full” it will start tweaking out. You need to recognize this and switch at a logical stop/start point. When starting a new context you need to:
So how do you reload a context without overwhelming it? I have a code helper add-in for the VB6 IDE that I added some features to:
These features are a minimum for efficient work. The add-in already had enhanced search-all and code navigation capabilities.
When I start a new context, first thing I would do is dump all of the classes and their public prototypes. Then I would upload the relevant files and tell it exactly what we are working on.
You have to keep a running map of the entire project in your head and a fair understanding of its architecture and what each class does. You can’t trust it to make all the decisions for you. It does a really good job, and was able to weave in some amazing features in very little code, but you still have to know what’s going on and make the proper suggestions and rejections. It was a painful process and I had to be at the top of my game that entire time to pull it off, but it really came out well. I am actually amazed by it.
There were a couple parts I knew were possible, but were above my direct
ability, such as the CallByNameEx and IDispatch proxy. Claude really nailed them. Accessing JS objects through IDispatch was particularly hairy to implement!
We ran into a bug deep into the heart of this code that AI could not solve. It had to do with updating a JS value through the COM proxy while still having it live in the JS engine. Finally I had the insight to not create a new CValue object, but instead update the existing one the JS engine already had a reference to. Another danger: Imagine your kitchen table filled with a pile of paperwork covering every inch, several feet high. AI can instantly generate massive blobs of text where you have no idea what’s inside there. It’s overwhelming. It made lots of decisions you will never know about. It’s essentially a black box. You may grow familiar with it as you make additions. In the beginning it’s just a blob, but its got electrolytes. Depending on your use case this can be very dangerous. Danger #3: there were things that it totally skipped or used placeholder stubs for that I only found much later. For example it decided to not implement any of the compound assignment or increment operators other than += and ++. I only found this out once I started actually using the engine and had a for loop trigger an endless loop as the implementation did nothing. You will have no warning things like this don’t exist! You can only find them through testing. Overall it was a very rewarding process. I now have the JS engine I have always wanted. This was a 20-year pain point for me. Finally relief! Some other posts that may be of interest:
Comments: (3)On 01.19.26 - 4:58pm Dave wrote:
On 01.21.26 - 7:31am Dave wrote:
On 01.22.26 - 8:44am Dave wrote:
|
About Me More Blogs Main Site |
|||