funny philisophical problem related is the paperclip problem
Chat GPT
Given that AI is the current fad, I thought I’d rant about it a bit. There’s been twice that I’ve experimented with AI when making software, and both times it has been a catastrophic failure.
Android Image Analysis
At my job, I researched how we could use the more basic image tools provided by Android in novel ways to help with our photogrammetric processing, primarily how to reduce our reliance on AR-Core which was becoming a performance bottleneck and causing issues for customers.
I was looking into leveraging CameraX’s Image analysis pipeline for various things. One of the major downsides, however, is that CameraX does NOT provide depth images (this is outside of the issue that phones don’t necessarily make this available). This data can only be retrieved with Camera2, an older and more obtuse API, but one that provides much more fine-grained access to camera functionalities than CameraX.
Some of the approaches I wanted to investigate required depth images, some didn’t, so I got familiar with both. As I was going to be doing various complicated things that I had never done before, I decided to see what Chat GPT had to say to see if it could at least speed up my development.
I was generally appaled.
At first, it was fine, at least just to see some small examples of CameraX and Camera2, but they were things I could also get from the official Android documentation. Anything past that, and ChatGPT consistently confused both Camera2 and CameraX in code, resulting in nothing useful. It got to the point where I wanted to see how bad it was. I specifically asked if depth was available with CameraX (which, see above, it is not), to which it said yes. The code it returned was hallucinated garbage. No matter how many times I told it that this was not possibly, to which it agreed and apparently being a “super advanced AI” would remember, would the next sentence spit out more hallucinated code.
After an hour or so I gave up on using it for anything like this, and got back to my work as usual, my first serious experimentation into using AI as a code assistant having a horrendous, yet expected, result.
Flutter Stopwatch Widget
Alright, maybe the previous topic was a bit complicated. This next one was really simple: I wanted the best way to have a stopwatch show with minimal code. While there’s a pretty good package that does this, I wanted something smaller for my use case using only the Stopwatch class.
I’ve had some history with Flutter, and it’s a love-hate relationship. It is by far the fastest framework to block out a cross-platform app with a finished look, but it can have a steep learning curve once you’re trying to make things performant or layouts that require heavy nesting of views.
A Flutter fundamental is the setState()
function. It’s the make-all break-all for updating the UI.
Here’s the code it spat out:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyStopwatch(),
);
}
}
class MyStopwatch extends StatefulWidget {
@override
_MyStopwatchState createState() => _MyStopwatchState();
}
class _MyStopwatchState extends State<MyStopwatch> {
Stopwatch _stopwatch = Stopwatch();
bool _isRunning = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Stopwatch Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Elapsed Time:',
style: TextStyle(fontSize: 20),
),
SizedBox(height: 10),
Text(
formatElapsedTime(_stopwatch.elapsedMilliseconds),
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _isRunning ? _stop : _start,
child: Text(_isRunning ? 'Stop' : 'Start'),
),
SizedBox(width: 20),
ElevatedButton(
onPressed: _reset,
child: Text('Reset'),
),
],
),
],
),
),
);
}
void _start() {
setState(() {
_isRunning = true;
});
_stopwatch.start();
}
void _stop() {
setState(() {
_isRunning = false;
});
_stopwatch.stop();
}
void _reset() {
setState(() {
_isRunning = false;
});
_stopwatch.reset();
}
String formatElapsedTime(int milliseconds) {
Duration duration = Duration(milliseconds: milliseconds);
String twoDigits(int n) => n.toString().padLeft(2, "0");
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
String twoDigitMilliseconds =
twoDigits((duration.inMilliseconds.remainder(1000) / 10).round());
return "$twoDigitMinutes:$twoDigitSeconds.$twoDigitMilliseconds";
}
}
For anyone that can’t be bothered to read the code, or who hasn’t spotted the issue: there’s incorrect use of setState(). It never actually updates the elapsed time in any way that the Flutter engine recognizes as a way to update the UI. Even after fenagling with ChatGPT in the chat for a bit, it could never really output working code.
This was a pretty easy excercise that I wanted to avoid doing myself, as I wanted to get the main bulk of the app done, and not this little visual aid, yet in the end it would have been much quicker if I had just done it myself.
Godot Shaders
Added on 2024-06-22 For a Godot plugin I’m working on, I needed for part of a shader I’m making to reduce the width of a Sprite3D by a certain amount.
It had originally proposed some very strange stuff of passing quite a few uniforms to get the size of the sprite, then reduce the UV in the vertex() { }
block to then change the readable UVs in the fragment() { }
part.
For those unaware, you can simply modify the VERTEX coords in vertex() { }
, or the UV directly in fragment() { }
.
I had to basically tune it into giving me a reasonable answer.
Again, AI can be useful, but you need to know the topic you are asking the chat tool about, as you are always going to have to validate what it spits out.
Something I recently saw: ChatGPT suggesting that I debug my shader with print statements… if you don’t know why that wouldn’t work, then you don’t know enough about shaders
Constant hallucinations
The worst is when you ask questions about compatability between languages; Java with Kotlin, Java with C++, etc. When asking about calling a Kotlin coroutine in Java, it mixed both languages together, confusing APIs that existed in one language, but not the other, or just inventing new ones.
It’s not useless, but it can’t make software
I do use Chat-GPT on occasion to quickly see how something may be used, generally an API, but the thing is that any answer I get, I will absolutely have to check. I treat it more like a instant-response Stack Overflow, but anyone that says it’s game changing is blowing it out their ass.
The irony is that NASA also double checked results when doing calculations on early computers. I highly doubt, however, that AI will ever really be perfected. I’ve heard many times in my life that “AI will take over everything!” and “it’s going to replace developers and engineers!”, yet every time the tools are pretty much the same. The only thing that’s different with this current cycle is the great increase in computing power and the shear amount of data that the “AI” models can be trained on. That’s it. This is not even getting into issues of self-pollution and AI degredation when trained on it’s own data (a result of so much AI content being posted, then being used as training data by data parsers to feed into AI training models).