Skip to content

ardeshir/Golang-Rust-Csharp-Comparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang, Rust, CSharp Comparison

A golang, rust, csharp fetch csv file parser with postgres db

Golang Test

These tests cover a few different scenarios:

  1. Testing with a valid URL and database connection string
  2. Testing with an invalid URL
  3. Testing with an invalid database connection string

Test Docs:

  • go test
Data inserted successfully!
Data inserted successfully!
--- FAIL: TestProcessCSVData (0.62s)
    main_test.go:15: Expected an error, but got none
FAIL
exit status 1
FAIL    csv_parser      0.995s 

Golang Web Service

  • Use go run main.go --web to expose :8080/api service

Rust Test

In these test functions, we create sample data for each test case and call the function being tested with the sample data. We then use assertions to check ## that the function behaves correctly for each test case.

CSharp Test

Test Docs:

Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     2, Skipped:     0, Total:     2, Duration: 814 ms - /Users/ardeshir/Golang-Rust-Csharp-Comparison/csharp/CsvParser.Tests/bin/Debug/net6.0/CsvParserTests.dll (net6.0)

Csharp : CsvParserWeb a web service option

  • Evolving the CLI to also run a Web Service with --web (or basic cli --url)
  • The webservice --web listense for param url /CsvParser?url=https://ardeshir.io.file.csv

Scripting Languages:

  • (for extra points, no guarantee of support ;P)

Python3 venv

Python Tests config

  • pip install pytest pytest-cov
  • pytest --cov=csv_parser tests/
============ test session starts  =======================
Data inserted successfully!

---------- coverage: platform darwin, python 3.11.1-final-0 ----------
Name            Stmts   Miss  Cover
-----------------------------------
csv_parser.py      58     15    74%
-----------------------------------
TOTAL              58     15    74%

===============short test summary info =======================
FAILED tests/test_csv_parser.py::test_print_table_api - AssertionError: assert 'id: 1' in 'Table: api\nid: 32 url: http://example.com name: Example API created: 1234567890 \n'
FAILED tests/test_csv_parser.py::test_process_csv_data - AssertionError: assert 7 == 3

TypeScript

TS Docs

(nvm is my choice of node manager)

  • nvm install v18
  • npm init
  • npm install -g ts-node
  • npm install --save express
  • npm install -g request
  • npm install --save-dev @types/request
  • npm install -g typescript
  • npm install --save yargs
  • npm install --save pg csv-parser jsonfile

To Prettier or not to prettier

  • npm install --save-dev prettier
  • prettier --write src/*.ts.

Eslint

  • npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
  • eslint --fix src/.ts | eslint src/.ts

Run

  • npm install
  • npx ts-node src/csv_parser.ts --web
Table: api
Data inserted successfully!

Simple C Version

  1. To compile and run the code, you will need to follow the following steps:
  2. Install the required dependencies:
  • libcurl: sudo apt-get install libcurl4-openssl-dev
  • libpq: sudo apt-get install libpq-dev
  • jansson: sudo apt-get install libjansson-dev
  • Create a Makefile with the following content:
CC = clang  
CFLAGS = -Wall -Wextra -pedantic -std=c11 -O2  
LDFLAGS = -lcurl -lpq -ljansson  
TARGET = program  
  
all: $(TARGET)  
  
$(TARGET): main.c  
	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)  
  
clean:  
	rm -f $(TARGET)  
  1. Save the C code to a file named main.c.
  • Run make command to compile the code.
  1. Run the compiled program by typing ./program in the terminal.
  2. If you want to pass a URL to process the CSV data from, you can pass it as a command-line argument.
  1. If you want to run the program as a web service, pass --web as a command-line argument. For example, ./main --web.