• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Go
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kilo text editor, from Build Your Own Text Editor, in Go

kilo text editor in Golang

I did Build Your Own Text Editor only in Go instead of C. I tried to keep the spirit of kilo: a single file of source code, everything as simple as possible.

I tried to check in after completing each step, but sometimes I combined a few steps, or fixed bugs between steps.

Compare C and Go

I have some experience with C, but I'm learning Go. I'd like to use this project to compare the two languages, as well as to internalize Go.

I found the two languages comparable in terms of expressiveness. I transliterated the C code almost directly into Go. There was little difference in line count in the end:

Language  Files  Code    Comment  Blank  Total
    Go      1     797      163     86     1044
     C      1     757      152    161     1068

That's according to sloc

Where I found Go Better

Go's range operator made most iterations much simpler.

Go's standard packages had a type bytes.Buffer that replaced struct ab in the C version.

Go's built-in string type was a wash for me: C kilo assumes 1-byte characters, and since I was just transliterating, I did the same in Go. I ended up using []byte types for a great deal of the code that dealt with ASCII-Nul-terminated-strings. It might be fun to convert to Go string and []rune and see how that works out.

Go's memory management was a net positive. Not having to realloc() all the time was easier.

Slices seem to work well, if you think of them as typed pointers-to-arrays.

The "useful zero value" for new variables means a lot less initialization happens than in C, with a lot less room for error.

Where I found Go Worse

C's looser idea of what comprises true and false in looping and conditional tests lets C Kilo do some interesting things that required extra bool variables in Go.

Go's Linux system call support seemed a lot less well documented, but kilo does do a lot of semi-undocumented things to begin with. Getting and setting terminal attributes, and getting into and out of raw mode always seems a bit sketchy.

C's preprocessor macros actually would made a little clearer code in the Go func editorPrompt(): I found it harder to express "control H" in Go.

C enums worked better than Go const. This is a bit disingenous, since a more idiomatic Go text editor would have several small packages. Per-package types and constants would overcome this objection.

More Repositories

1

php-malware-analysis

Deobfuscation and analysis of PHP malware captured by a WordPress honey pot
PHP
123
star
2

reverse-php-malware

De-obfuscate and reverse engineer PHP malware
PHP
75
star
3

userlandexec

userland exec for Linux x86_64
C
51
star
4

ssh-tarpit-behavior

Results of running endlessh to tarpit ssh scanners
Shell
42
star
5

NudeDetectorPHP

PHP implementation of Rigan Ap-Apid's "An Algorithm for Nudity Detection"
PHP
19
star
6

crc32-file-collision-generator

Create files whose CRC32 value matches that of another file
Go
18
star
7

malware-phylogeny

malware phylogeny for WSO web shell, Shellbot IRC bot and algorithm
Perl
16
star
8

interviewquestions

Links to my interview question repos
14
star
9

random-credit-card-numbers

Generate unique credit card numbers that pass the Luhn check
Python
7
star
10

GoKilo

Kilo text editor, refactored into Go
Go
7
star
11

udp-echo-server

Golang echo server, using UDP
Go
7
star
12

infinite-fake-website

Lure SEO spammers down a hole with no bottom
PHP
7
star
13

binary_tree

Consolidated binary tree interview questions
Go
6
star
14

station

BME280, Raspberry Pi atmospheric data collection system
Python
4
star
15

tableaux-in-go

Prove propositional logic tautologies via Smullyan's tableaux method
Go
4
star
16

tree-pattern-matching

Hoffman and O'Donnel's "Pattern matching in trees" implemented in C
C
4
star
17

crapterpreter

An unremarkable interpreted programming language
C
3
star
18

userlandexec-arm

userland exec for Linux ARM v7
C
3
star
19

squava

Command line Squava game in Go, Alpha-beta minimax and Monte Carlo Tree Search
Go
3
star
20

any-combinatory-logic

Combinatory Logic Interpreter with user-definable primitives and abstraction algorithms
C
3
star
21

arithmetic-parser

Golang arithmetic expression parser and evaluator
Go
2
star
22

lru-cache

Programming job interview design question - least recently used cache
Go
2
star
23

list-segment-implementation

A deliberately limited re-implementation of the "ls" command
C
2
star
24

combinatory-logic

Full featured combinatory logic interperter
C
2
star
25

self-replicating-programs

Assorted self replicating programs: python, bash, php, m4, perl, awk, gpp
Shell
2
star
26

huffman

Programming job interview question, Huffman encoding
Go
2
star
27

tcp-self-connect

Illustrate TCP client self-connect/simultaneous open in ephemeral port range
C
2
star
28

lisp-in-python-in-go

Peter Norvig's Lisp in Python reimplemented in Go
Go
2
star
29

commonwords

Revisiting Knuth and McIlroy's word count problem, in Go
Go
1
star
30

jobscheduler

Job scheduler interview question
Go
1
star
31

quack

Queue data structure programmin job interview question
Go
1
star
32

cryptopals

Golang implementation of the cryptopals cryptography challenges
Go
1
star
33

functional_dequeue

Investigations into the 3-stack constant time/space double-ended queue
Go
1
star
34

monte-carlo-lock

Emulations of "machines" from Raymond Smullyan's book, The Lady or The Tiger
HTML
1
star
35

bitops

Solution to, and analysis of, a programmin job interview question
Go
1
star
36

linked_lists

Linked list interview questions and puzzles in Go
Go
1
star
37

divisionwithout

Programing puzzle, integer division without using built-in division operator
Go
1
star
38

nine-board

Nine-board Tic Tac Toe in your browser
HTML
1
star
39

Self-replicating-go

Self-replicating go program
Go
1
star
40

scapegoat-trees

Scapegoat Trees binary tree algorithm
Go
1
star
41

swapbits

Daily coding problems interview question: swap even and odd bits in 8-bit integer
Go
1
star
42

tree_symmetry

Daily coding problem: determine if a k-ary tree is symmetric
Go
1
star
43

curried-arithmetic

Programming interview question involving curried functions
Go
1
star
44

utf8validator

UTF-8 byte stream validation programming job interview question
Go
1
star
45

lambda-calculator

lambda calculus interpreter
C
1
star
46

postorder-tree-traversal

Recreate binary tree from its post-order traversal
Go
1
star
47

arithmetic-expressions

Arithmetic order of operations expression evaluator
Go
1
star
48

network-worm-simulator

Discrete time step simulation of network worms and fully-connected networks.
HTML
1
star
49

graycode

Developer job interview question about generating Gray Code values
Go
1
star
50

bcd2

BCD arithmetic experiments
Go
1
star
51

interpolating

caculate numerical values of an interpolating polynomial passing through N points
Go
1
star
52

reservoir-sampling

Reservoir sampling as a Unix filter program
Go
1
star
53

xor-decoding

Semi-automatically decode xor-encoded text files, including key discovery
C
1
star
54

propositional-logic-go

Read propositional logic expressions, and reprint them, Golang version
Go
1
star
55

vigenere-ciphering-deciphering

Classical ciphers: encoding, decoding and key recovery, all in Go
Go
1
star