DEV Community

abdulrazak maulid haji
abdulrazak maulid haji

Posted on

Introduction to Programming in Computer Systems

Programming lies at the heart of computer systems, orchestrating the intricate dance between input, output, process, storage, and communication. In this article, we'll explore how these fundamental components interact, using examples in Python, Go, and JavaScript to illustrate their roles.

Input:

Input serves as the gateway through which data enters the system, initiating processes and interactions. This can range from user input via keyboard or mouse to data from sensors, files, or network streams.

# Python example
user_input = input("Enter your name: ")
print("Hello,", user_input)
Enter fullscreen mode Exit fullscreen mode
// Go example
package main

import "fmt"

func main() {
    var userInput string
    fmt.Print("Enter your name: ")
    fmt.Scanln(&userInput)
    fmt.Println("Hello,", userInput)
}
Enter fullscreen mode Exit fullscreen mode
// JavaScript example
let userInput = prompt("Enter your name:");
console.log("Hello, " + userInput);
Enter fullscreen mode Exit fullscreen mode

Output:

Output represents the result or response generated by the system, conveying information to users, other systems, or devices.

# Python example
print("Hello, world!")
Enter fullscreen mode Exit fullscreen mode
// Go example
package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}
Enter fullscreen mode Exit fullscreen mode
// JavaScript example
console.log("Hello, world!");
Enter fullscreen mode Exit fullscreen mode

Process:

Process involves manipulating and transforming data according to predefined algorithms and logic, enabling the computer to perform tasks and solve problems.

# Python example
num1 = 5
num2 = 3
result = num1 + num2
print("The sum is:", result)
Enter fullscreen mode Exit fullscreen mode
// Go example
package main

import "fmt"

func main() {
    num1 := 5
    num2 := 3
    result := num1 + num2
    fmt.Println("The sum is:", result)
}
Enter fullscreen mode Exit fullscreen mode
// JavaScript example
let num1 = 5;
let num2 = 3;
let result = num1 + num2;
console.log("The sum is:", result);
Enter fullscreen mode Exit fullscreen mode

Storage:

Storage entails preserving data for future use, whether temporarily in memory (RAM) or permanently on storage devices (e.g., hard drives, SSDs).

# Python example
my_list = [1, 2, 3, 4, 5]
Enter fullscreen mode Exit fullscreen mode
// Go example
package main

func main() {
    mySlice := []int{1, 2, 3, 4, 5}
}
Enter fullscreen mode Exit fullscreen mode
// JavaScript example
let myArray = [1, 2, 3, 4, 5];
Enter fullscreen mode Exit fullscreen mode

Communication:

Communication enables the exchange of data and information between different components, systems, or users, facilitating collaboration and interaction.

# Python example (using sockets for network communication)
import socket

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('localhost', 12345))
server_socket.listen(1)

client_socket, addr = server_socket.accept()
print("Connection from", addr)

data = client_socket.recv(1024)
print("Received:", data.decode())

client_socket.close()
server_socket.close()
Enter fullscreen mode Exit fullscreen mode
// Go example (using HTTP for web communication)
package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}
Enter fullscreen mode Exit fullscreen mode
// JavaScript example (using WebSocket for real-time communication)
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });

  ws.send('something');
});
Enter fullscreen mode Exit fullscreen mode

Understanding these components and their interplay is fundamental to harnessing the full potential of programming in computer systems. Whether you're manipulating data, interfacing with hardware, or building complex systems, programming serves as the bridge that transforms ideas into reality.

Top comments (0)