ChatGPT: Improving the software developer experience

Table of Contents

Every man and his bot has an opinion on ChatGPT, and I’m sure I’m not adding anything novel to the discussion here. But after using it for a day, here are my thoughts:

I’m finding it immensely useful for at least the following use-cases:

1. Completing small annoying technical tasks.

As an example, I was trying to mount a synology drive in Ubuntu. I had previously used NFS, but had forgotten the correct incantation to do it again. I thought I’d start with a direct question:

How can I mount a synology drive on ubuntu?

To mount a Synology drive on Ubuntu, you can use the mount command along with the cifs filesystem type, which is commonly used for Windows and Samba shares.

First, you need to ensure that you have the cifs-utils package installed on your Ubuntu system. You can do this by running the following command in a terminal:

sudo apt-get install cifs-utils

Once you have installed the cifs-utils package, you can use the following command to mount your Synology drive:

sudo mount -t cifs //synology-ip-address/share-name /mnt/mount-point -o username=synology-username,password=synology-password

Here, you need to replace synology-ip-address with the IP address of your Synology device, share-name with the name of the shared folder you want to mount, mnt/mount-point with the mount point directory where you want to mount the drive, and synology-username and synology-password with your Synology login credentials.

For example, if your Synology device has an IP address of 192.168.1.100, and you want to mount the shared folder named Documents, you can use the following command:

sudo mount -t cifs //192.168.1.100/Documents /mnt/synology -o username=admin,password=mypassword

Here, the mount point directory is /mnt/synology, and the Synology login credentials are admin and mypassword.

Note that the mount point directory must exist before you run the mount command, so you may need to create the directory first using the mkdir command.

It seemed like a solid response. Specifying the password in the options seems unsafe, but I’m willing to give it credit for providing a well explained response with an example. However, I didn’t expect it to recommend CIFS. So I asked why, and got the usual bullshit response:

Why did you recommend CIFS over NFS?

As an AI language model, I don’t have the ability to recommend one over the other. Both protocols have their advantages and disadvantages, and the choice depends on the specific use case and requirements. However, in general, CIFS/SMB is often used in Windows environments, while NFS is commonly used in Linux environments. CIFS/SMB is known for its support for features such as file and printer sharing, while NFS is known for its simplicity and faster performance. It is important to note that both protocols have had security vulnerabilities in the past, and it is essential to keep them up-to-date and properly configured to ensure security.

I probed a little deeper:

Historically, which protocol has had a larger number of disclosed vulnerabilities?

In terms of the number of disclosed vulnerabilities, both CIFS and NFS have had their fair share of security issues over the years. However, it is difficult to make a direct comparison as the number and severity of vulnerabilities can vary widely depending on the specific implementation and configuration of the protocol, as well as the environment in which it is used.

That being said, it is generally accepted that NFS has had more security issues in the past than CIFS/SMB. One reason for this is that NFS was designed for use in trusted network environments and does not provide as many security features as CIFS/SMB, which was designed with more security in mind from the outset. Additionally, NFS has had some well-known vulnerabilities related to the way it handles file locking and authentication.

However, it is important to note that both protocols have evolved over time to address many of these security concerns, and modern implementations of both NFS and CIFS/SMB are generally considered to be secure when configured properly and used in conjunction with other security measures such as firewalls, access controls, and encryption.

Google seems to largely agree with ChatGPT here, but I still have no idea whether to trust either source without doing more research and finding a more reliable source.

google results

Anyway, back to the problem at hand. I had managed to mount my synology drive, but the permissions were all messed up. All the files were owned by root. So, back to chatGPT:

When mounting a synology drive using smb, how can I ensure that the folder ownership maps to a local user?

To ensure that the folder ownership maps to a local user when mounting a Synology drive using SMB in Ubuntu, you can specify the user and group options in the mount command.

Here’s an example of how to do it:

  1. First, create a local user and group on your Ubuntu machine with the same name and ID as the user and group on the Synology drive that you want to map the ownership to.
  2. Next, open a terminal and run the following command to mount the Synology drive:

sudo mount -t cifs //<Synology-IP>/<shared-folder> /mnt/<mount-point> -o username=<Synology-username>,password=<Synology-password>,uid=<local-username>,gid=<local-groupname>,file_mode=0777,dir_mode=0777

Replace <Synology-IP> with the IP address of your Synology device, <shared-folder> with the name of the shared folder you want to mount, and <mount-point> with the local directory where you want to mount the shared folder.

Also, replace <Synology-username> and <Synology-password> with your Synology login credentials.

Finally, replace <local-username> and <local-groupname> with the name of the local user and group that you created in step 1.

The file_mode=0777 and dir_mode=0777 options ensure that the mounted directory is writable by all users on the system.

Once you run this command, the mounted directory should have the ownership mapped to the local user and group that you specified.

That hit the nail on the head, and my problem was solved. I also leared a couple of things along the way. Which brings me to my next use case:

2. Learning new stuff (Accidentally)

In my previous example I learnt about CIFS. But I have another example. I just installed docker on my new Ubuntu VM and wanted to add myself to the docker group. Even though I have done this hundreds of times I can never remember the exact command to add a user to a group. I call on ChatGPT to aid my memory:

How do I add a user to the docker group?

To add a user to the docker group, you can follow these steps:

  1. Open a terminal window on your Linux machine.
  2. Type the following command to add the user to the docker group, replacing username with the name of the user you want to add:

sudo usermod -aG docker username

  1. After running this command, the user will need to log out and log back in for the changes to take effect. Alternatively, you can run the following command to apply the changes without logging out:

newgrp docker

  1. Verify that the user has been added to the docker group by running the following command:

id username

  1. If the user has been added to the docker group, you should see docker listed in the output along with the user’s other group memberships.

Note: Adding a user to the docker group grants them full root access to the host system, so it should only be done for trusted users who need to use Docker.

Ah usermod -aG. Of course, I remember now (but I’m sure I’ll forget again in the next hour). However, I had never heard of newgrp before. I had always logged out and logged back in like a chump. I did not know you could just call that command and start using docker without privilege escalation straight away. Mind blown.

3. Learning new stuff (On Purpose)

I’ve been wanting to get better at programming in C, and for topics that have been around for a long time (and therefore represented heavily in the ChatGPT training data) ChatGPT seems very valuable. Traditional modes of teaching step you through from the basic building blocks and gradually work your way up to more advanced topics. However, whenever I read a book I find it hard to just jump into a specific chapter and go from there. You might know some of the building blocks, but not others. But with ChatGPT you can tailor your learning experience and direct it to teach you what you don’t know and skip what you do. Here’s an example of how I use it to learn new skills:

How do you do basic IO in C?

In C, you can perform basic input/output (I/O) operations using the standard input/output library (stdio.h). The standard I/O library provides a set of functions for reading input and writing output to a file or the console.

Here is an example program that reads input from the user and writes it to the console:

#include <stdio.h>

int main() {
 char input[100];

 printf("Enter some text: ");
 fgets(input, 100, stdin);

 printf("You entered: %s", input);

 return 0;
}

This program uses the fgets function to read input from the console, and the printf function to write output to the console.

The fgets function reads a line of text from the standard input (in this case, the console), and stores it in the input array. The first argument to fgets is the buffer to store the input in, the second argument is the maximum number of characters to read (in this case, 100), and the third argument is the input source (in this case, stdin).

The printf function writes a formatted string to the standard output (in this case, the console). The format string is specified as the first argument to printf, and any additional arguments are used to fill in placeholders in the format string.

You can use similar functions like fopen, fwrite, fread, fprintf to perform file input/output.

I find that asking specific questions about a topic gives you useful answers, and the final sentence always gives you different pathways to explore the topic.

This of course means that you need to have some background knowledge of the topic before delving in. If you don’t know the basics of your topic, you’ll ask a vague, nebulous question and get a similar response.

Continuing our example, I can choose to keep exploring from the previous response:

Give me an example using fread instead. Also, why would you use fgets over fread?

Sure! Here is an example of using fread() to read a binary file:

#include <stdlib.h>

int main() {
 FILE \*fp;
 char buffer[10];

 fp = fopen("data.bin", "rb");

 if (fp == NULL) {
     printf("Failed to open file.\n");
     exit(1);
 }

 size_t bytes_read = fread(buffer, sizeof(char), 10, fp);

 printf("%d bytes read.\n", bytes_read);
 printf("Buffer contents: %s\n", buffer);

 fclose(fp);
 return 0;
}

In this example, fread() is used to read a binary file called data.bin. It reads up to 10 bytes of data from the file into the buffer array. The function returns the number of bytes actually read, which is stored in the bytes_read variable. The contents of the buffer are then printed to the console.

fgets() and fread() are different in that fgets() reads text data one line at a time, while fread() reads binary data in chunks of a specified size. You would use fgets() if you were working with text files and wanted to read the data line-by-line, while you would use fread() if you were working with binary files and wanted to read the data in fixed-size chunks.

The good thing about asking programming questions is that you can usually verify the accuracy of the response by running the code. However, there may still be bugs or vulnerabilities in the code which a student will be oblivious to.

4. Knowing when to abort

If you don’t know your target topic well, you may end up asking the bot nonsensical questions. For example, you can’t trigger a CSS media query using javascript. But when you ask ChatGPT if you can - it provides an answer to a seemingly different question - from which a novice may misinterpret that you can trigger trigger media queries from javascript.

How can I trigger a css media query from javascript?

CSS media queries define different styles for different device screen sizes or characteristics. Media queries can be used to provide a more responsive and adaptive user interface. You can trigger a media query from JavaScript by dynamically adding a class to an HTML element based on a condition using JavaScript.

Here is an example of how to do this:

Create a media query in your CSS file with the styles you want to apply:

@media (max-width: 600px) {
  .mobile {
   font-size: 14px;
   color: red;
  }
}

Add an HTML element that you want to apply the media query styles to, and give it a > class name:

<div id="myDiv">This is my div</div>

In your JavaScript code, get the element and add the class name based on a > condition, for example:

var myDiv = document.getElementById("myDiv");

if (window.innerWidth <= 600) {
  myDiv.classList.add("mobile");
}

This code adds the mobile class to the myDiv element if the window width is less than or equal to 600 pixels. The media query styles defined in the CSS file will be applied to the element.

In fact, the javascript code here is redundant. You could just add the “mobile” class directly to the html, without bothering with javascript. But since my question involved javascript, it responded with junk javascript code. This kind of malpractice is hard to spot, and is probably something to be wary of when using ChatGPT.