Posted: . At: 10:27 AM. This was 2 years ago. Post ID: 16905
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


GitHub Copilot and Visual Studio Code. Is this the future of programming?


GitHub Copilot and Visual Studio Code are an excellent combination for programming. This is able to use an AI companion to write code assisting the development of a program. This is not perfect, it seems to have issues with asm statements in C code, but otherwise, it works fine. The future of programming is AI. Instead of hiring an actual programmer, just use AI to write code. This is amazing. Instead of needing programmers in India to write your code, they can be supplanted by a machine. Of course, you still need a programmer to proofread the code, but this is necessary in any case. The code generated by this system is very good, despite the issues with asm statements, but I guess this is a niche situation anyway. The program below was written in Visual Studio Code and with the assistance of AI. And it works just fine.

skynet.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdlib.h>
 
/* This is the function that will be called when the program is run.
* It takes no arguments and returns an integer.
*/
 
int main (void) {
 
/* This is the variable that will be used to store the user's input.
* It is declared as a pointer to a character, which is a string.
*/
 
    struct skynet {
        char *name;
        int age;
        char *gender;
    };
 
    typedef struct skynet skynet;
    skynet *skynet1;
    skynet1 = malloc(sizeof(skynet));
    skynet1->name = "John";
    skynet1->age = 20;
    skynet *skynet2;
    skynet2 = malloc(sizeof(skynet));
    skynet2->name = "Jane";
    skynet2->age = 21;
    skynet *skynet3;
    skynet3 = malloc(sizeof(skynet));
    skynet3->name = "Jack";
    skynet3->age = 22;
    skynet *skynet4;
    skynet4 = malloc(sizeof(skynet));
    skynet4->name = "Jill";
    skynet4->age = 23;
    skynet *skynet5;
    skynet5 = malloc(sizeof(skynet));
    skynet5->name = "Jenny";
    skynet5->age = 24;
    skynet *skynet6;
    skynet6 = malloc(sizeof(skynet));
    skynet6->name = "jane";
    skynet6->age = 25;
    skynet *skynet7;
    skynet7 = malloc(sizeof(skynet));
    skynet7->name = "Joan";
    skynet7->age = 26;
    skynet *skynet8;
    skynet8 = malloc(sizeof(skynet));
    skynet8->name = "Jessie";
    skynet8->age = 27;
    skynet *skynet9;
    skynet9 = malloc(sizeof(skynet));
    skynet9->name = "Kyle";
    skynet9->age = 28;
    skynet *skynet10;
    skynet10 = malloc(sizeof(skynet));
    skynet10->name = "Jason";
    skynet10->age = 29;
    skynet *skynet11;
    skynet11 = malloc(sizeof(skynet));
    skynet11->name = "Richard";
    skynet11->age = 30;
    skynet *skynet12;
    skynet12 = malloc(sizeof(skynet));
    skynet12->name = "Micheal";
    skynet12->age = 31;
    skynet *skynet13;
    skynet13 = malloc(sizeof(skynet));
    skynet13->name = "Justin";
    skynet13->age = 32;
 
    printf(" %s %d ", skynet1->name, skynet1->age);
    printf(" %s %d ", skynet2->name, skynet2->age);
    printf(" %s %d ", skynet3->name, skynet3->age);
    printf(" %s %d ", skynet4->name, skynet4->age);
    printf(" %s %d ", skynet5->name, skynet5->age);
    printf(" %s %d ", skynet6->name, skynet6->age);
    printf(" %s %d ", skynet7->name, skynet7->age);
    printf(" %s %d ", skynet8->name, skynet8->age);
    printf(" %s %d ", skynet9->name, skynet9->age);
    printf(" %s %d ", skynet10->name, skynet10->age);
    printf(" %s %d ", skynet11->name, skynet11->age);
    printf(" %s %d ", skynet12->name, skynet12->age);
    printf(" %s %d ", skynet13->name, skynet13->age);
 
    return 0;
}

This is another program written with AI assistance, this will open a text file and tell you the filesize in bytes.

size.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char *argv[])
{
    const char *filename = "skynet.c";
    long int len;
    FILE *fp = fopen(filename, "r");
    if (fp == NULL) {
        fprintf(stderr, "Error: cannot open file '%s'", filename);
        exit(EXIT_FAILURE);
    }
    fseek(fp, 0, SEEK_END);
    len = ftell(fp);
    fclose(fp);
    printf("The file '%s' is %ld bytes long (not including the null terminator) ... ", filename, len);
    printf("File '%s' opened successfully\n", filename);
    printf("File size: %d bytes (approx.)\n", len);
 
    return 0;
}

So, this is very useful indeed, getting the filesize of a text file with the ftell() function is very easy using C. I just wish the foreach function was available in ANSI C. This is annoying.

Anyway, give this a try yourself, it is really amazing what it can do.

https://docs.github.com/en/copilot/getting-started-with-github-copilot/getting-started-with-github-copilot-in-visual-studio-code.

And yet another example of programming with Copilot. This is a simple program to check if an environment variable is set and then print the value.

pontiac.c
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdlib.h>
#include <stdio.h>
 
int main (int argc, char *argv[])
{
    char *pontiac = getenv("PONTIAC");
    if (pontiac == NULL) {
        printf("PONTIAC is not set  :-( \r");
    } else {
        printf("PONTIAC is set to %s \n", pontiac);
    }
    return 0;
}

The key feature of GitHub Copilot is the ability to type a natural language query in a comment and then the system will generate code for you.

cpu.c
1
2
3
4
5
6
7
8
9
10
11
12
// Source code to print information about the Linux kernel and CPU.
// Path: cpu.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
 
int main(int argc, char *argv[])
{
    struct utsname uts;
    uname(&uts);
    printf("

This is nice to use if the programmer is stuck and wants to program something using some starting code and then program the rest of the code once the starting code has been written.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.