Rendering Effects of Different Programming Languages

The following are practical code snippets for 10 common programming languages, all classic introductory scenarios (including syntax features and core functions).

Python (Data Processing + List Comprehensions)

# Function: Calculate the sum of squares of even numbers from 1-10 (demonstrates list comprehensions, built-in functions)
def calculate_even_square_sum():
    # List comprehension to filter even numbers and calculate squares
    even_squares = [x*x for x in range(1, 11) if x % 2 == 0]
    return sum(even_squares)

# Call the function and print the result
result = calculate_even_square_sum()
print(f"Sum of squares of even numbers from 1-10: {result}")  # Output: 220

JavaScript (DOM Manipulation + Arrow Functions)

// Function: Clicking a button to modify page text (demonstrates DOM manipulation, arrow functions, event listening)
document.addEventListener('DOMContentLoaded', () => {
  // Get button and text elements
  const btn = document.getElementById('changeTextBtn');
  const textElem = document.getElementById('targetText');
  
  // Arrow function binding click event
  btn.addEventListener('click', () => {
    const newText = `Updated time: ${new Date().toLocaleString()}`;
    textElem.textContent = newText; // Modify text content
    textElem.style.color = '#2c3e50'; // Modify style
  });
});

// HTML structure (needs to be used in conjunction)
/*
<button id="changeTextBtn">Click to Update</button>
<p id="targetText">Waiting for update...</p>
*/

Go (Structs + Interfaces)

// Function: Define animal interface and implementation (demonstrates Go's implicit interface implementation feature)
package main

import "fmt"

// Define interface
type Animal interface {
	Sound() string // Interface method
}

// Define struct
type Dog struct {
	Name string
}

type Cat struct {
	Name string
}

// Dog implements the Animal interface
func (d Dog) Sound() string {
	return fmt.Sprintf("%s: Woof Woof", d.Name)
}

// Cat implements the Animal interface
func (c Cat) Sound() string {
	return fmt.Sprintf("%s: Meow Meow", c.Name)
}

func main() {
	animals := []Animal{Dog{"Wangcai"}, Cat{"Mijiang"}}
	for _, animal := range animals {
		fmt.Println(animal.Sound()) // Polymorphic call
	}
}

Java (Classes and Inheritance)

// Function: Abstract class and subclass implementation (demonstrates core OOP features)
abstract class Shape {
    // Abstract method (subclasses must implement)
    public abstract double calculateArea();
}

// Circle subclass
class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double calculateArea() {
        return Math.PI * radius * radius; // Circle area formula
    }
}

// Rectangle subclass
class Rectangle extends Shape {
    private double width;
    private double height;

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public double calculateArea() {
        return width * height; // Rectangle area formula
    }
}

public class Main {
    public static void main(String[] args) {
        Shape circle = new Circle(5);
        Shape rectangle = new Rectangle(4, 6);
        
        System.out.printf("Circle area: %.2f\n", circle.calculateArea()); // 78.54
        System.out.printf("Rectangle area: %.2f\n", rectangle.calculateArea()); // 24.00
    }
}

C++ (Template Functions + STL)

// Function: Template functions + vector containers (demonstrates generic programming and STL usage)
#include <iostream>
#include <vector>
#include <algorithm> // For sort function

// Template function: Print any type of vector
template <typename T>
void printVector(const std::vector<T>& vec) {
    for (const auto& elem : vec) {
        std::cout << elem << " ";
    }
    std::cout << std::endl;
}

int main() {
    // Integer vector
    std::vector<int> nums = {3, 1, 4, 1, 5, 9};
    std::cout << "Before sorting: ";
    printVector(nums);
    
    // STL sort function
    std::sort(nums.begin(), nums.end());
    std::cout << "After sorting: ";
    printVector(nums);
    
    return 0;
}

C# (LINQ Queries + Object-Oriented Programming)

// Function: LINQ query to filter object lists (demonstrates C# LINQ features)
using System;
using System.Collections.Generic;
using System.Linq;

// Define student class
public class Student {
    public string Name { get; set; }
    public int Age { get; set; }
    public double Score { get; set; }
}

class Program {
    static void Main() {
        // Student data list
        List<Student> students = new List<Student> {
            new Student { Name = "Zhang San", Age = 18, Score = 92.5 },
            new Student { Name = "Li Si", Age = 19, Score = 88.0 },
            new Student { Name = "Wang Wu", Age = 18, Score = 95.0 }
        };

        // LINQ query: Filter students aged 18 with scores ≥ 90
        var qualifiedStudents = from s in students
                               where s.Age == 18 && s.Score >= 90
                               select new { s.Name, s.Score };

        // Print results
        Console.WriteLine("Qualified students under 18:");
        foreach (var student in qualifiedStudents) {
            Console.WriteLine($"Name: {student.Name}, Score: {student.Score}");
        }
    }
}

PHP (Array Operations + File Reading)

<?php
// Function: Array processing + file content reading (demonstrates PHP array features and file operations)
header("Content-Type: text/html; charset=utf-8");

// Associative array: Store user information
$users = [
    ["name" => "Xiaoming", "gender" => "Male", "age" => 22],
    ["name" => "XiaoHong", "gender" => "Female", "age" => 20]
];

// Traverse array and print
echo "<h3>User List</h3>";
foreach ($users as $user) {
    echo "Name: {$user['name']}, Gender: {$user['gender']}, Age: {$user['age']}<br>";
}

// Read file content (ensure the file exists)
$filePath = "test.txt";
if (file_exists($filePath)) {
    $content = file_get_contents($filePath);
    echo "<h3>File Content</h3>";
    echo nl2br($content); // Preserve line breaks
} else {
    echo "File not found!";
}
?>

Ruby (Iterators + Hash Tables)

# Function: Hash table operations + iterators (demonstrates Ruby's concise syntax)
# Define hash table: Store product information
products = {
  "apple" => { name: "Apple", price: 5.99, stock: 100 },
  "banana" => { name: "Banana", price: 3.99, stock: 150 },
  "orange" => { name: "Orange", price: 4.99, stock: 80 }
}

# Iterate hash table: Print products with stock ≥ 100
puts "Products with sufficient inventory:"
products.each do |code, info|
  if info[:stock] >= 100
    puts "#{info[:name]} - Price: #{info[:price]} Yuan, Stock: #{info[:stock]} Pieces"
  end
end

# Calculate total price of all products (assuming buy one each)
total_price = products.sum { |code, info| info[:price] }
puts "\nTotal price for buying one each: #{total_price.round(2)} Yuan"

TypeScript (Interfaces + Type Definitions)

// Function: Interface definition + type constraints (demonstrates TS static typing features)
// Define user interface
interface User {
  id: number;
  username: string;
  email: string;
  isActive?: boolean; // Optional property
}

// Define function: Format user information
function formatUser(user: User): string {
  const status = user.isActive ? "Active" : "Inactive";
  return `ID: ${user.id}, Username: ${user.username}, Email: ${user.email}, Status: ${status}`;
}

// Instantiate user object
const user1: User = {
  id: 1,
  username: "johndoe",
  email: "john@example.com",
  isActive: true
};

// Call function and print
console.log(formatUser(user1));
// Output: ID: 1, Username: johndoe, Email: john@example.com, Status: Active

HTML+CSS+JS (Frontend Interactive Component)

<!-- Function: Simple counter component (demonstrates frontend trio cooperation) -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Counter</title>
    <style>
        .counter {
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 18px;
            padding: 20px;
            max-width: 300px;
            margin: 20px auto;
            border: 1px solid #eee;
            border-radius: 8px;
        }
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            background: #2c3e50;
            color: white;
            cursor: pointer;
        }
        .btn:hover {
            background: #34495e;
        }
        #count {
            font-weight: bold;
            color: #e74c3c;
        }
    </style>
</head>
<body>
    <div class="counter">
        <button class="btn" id="decrease">-</button>
        <span>Current count: <span id="count">0</span></span>
        <button class="btn" id="increase">+</button>
    </div>

    <script>
        let count = 0;
        const countElem = document.getElementById('count');
        const increaseBtn = document.getElementById('increase');
        const decreaseBtn = document.getElementById('decrease');

        // Increase counter
        increaseBtn.addEventListener('click', () => {
            count++;
            countElem.textContent = count;
        });

        // Decrease counter (not less than 0)
        decreaseBtn.addEventListener('click', () => {
            if (count > 0) count--;
            countElem.textContent = count;
        });
    </script>
</body>
</html>

Code Without Specifying Programming Language Type

# Function: Calculate the sum of squares of even numbers from 1-10 (demonstrates list comprehensions, built-in functions)
def calculate_even_square_sum():
    # List comprehension to filter even numbers and calculate squares
    even_squares = [x*x for x in range(1, 11) if x % 2 == 0]
    return sum(even_squares)

# Call the function and print the result
result = calculate_even_square_sum()
print(f"Sum of squares of even numbers from 1-10: {result}")  # Output: 220

Markdown Syntax Rendering Effects





Here are **complete standard Markdown syntax examples** (including core syntax + common extended syntax), all compatible with Hugo (and mainstream Markdown renderers), can be directly used for blog writing, document writing, and combined with the previous code highlighting configuration to perfectly render:

## Basic Syntax
### Title (Sixth Level)
Syntax: `# One-level title` ~ `###### Six-level title` (`#` followed by a space)
```markdown
# One-level title (Maximum)
## Two-level title
### Three-level title
#### Four-level title
##### Five-level title
###### Six-level title (Minimum)

Rendering Effect:

One-level title (Maximum)
Two-level title
Three-level title
Four-level title
Five-level title
Six-level title (Minimum)

Paragraphs and Line Breaks

  • Paragraph: Directly input text, paragraphs are separated by a blank line;
  • Line break: Add two spaces at the end of the line + enter (or directly blank line).
This is the first paragraph, containing regular text content.
Line end with two spaces  (here are two spaces)
Achieve forced line break.

This is the second paragraph(blank line separated from the previous paragraph), Markdown will automatically handle paragraph spacing.

Rendering Effect:

This is the first paragraph, containing regular text content.
Line end with two spaces
Achieve forced line break.

This is the second paragraph(blank line separated from the previous paragraph), Markdown will automatically handle paragraph spacing.

Text Emphasis (Bold/Italic/Delete Line)

*Italic text* (single asterisk)
_Italic text_ (single underscore)
**Bold text** (double asterisks)
__Bold text__ (double underscores)
***Bold and Italic text*** (three asterisks)
___Bold and Italic text___ (three underscores)
~~Strikethrough text~~ (two wave brackets)

Rendering Effect:

Italic text
Italic text
Bold text
Bold text
Bold and Italic text
Bold and Italic text
Strikethrough text

Lists (Ordered/Unordered/Nested)

Unordered List

Syntax: -/*/+ + space (three have the same effect)

- Unordered list item 1 (hyphen)
* Unordered list item 2 (asterisk)
+ Unordered list item 3 (plus sign)

Rendering Effect:

  • Unordered list item 1 (hyphen)
  • Unordered list item 2 (asterisk)
  • Unordered list item 3 (plus sign)

Ordered List

Syntax: “Number + . + space” (numbers do not need to be continuous, rendered automatically sorted)

1. Ordered list item 1
2. Ordered list item 2
5. Ordered list item 3 (number is not continuous, rendered as 3)

Rendering Effect:

  1. Ordered list item 1
  2. Ordered list item 2
  3. Ordered list item 3 (number is not continuous, rendered as 3)

Nested List (Indent 4 spaces or 1 tab character)

- Outer unordered list
    1. Inner ordered list 1
    2. Inner ordered list 2
        - Inner nested unordered list
- Outer unordered list 2

Rendering Effect:

  • Outer unordered list
    1. Inner ordered list 1
    2. Inner ordered list 2
      • Inner nested unordered list
  • Outer unordered list 2

Syntax: [Link Text](Link Address "Optional Title") (Title shows on hover)

[Hugo Official Documentation](https://gohugo.io/ "Hugo Official Website")
[My Blog](https://example.com) (No Title)

Rendering Effect:

Hugo Official Documentation
My Blog (No Title)

Syntax: First define [Link Identifier]: Link Address "Optional Title", then use [Link Text][Link Identifier]

This is [Hugo Documentation][hugo-docs], this is [GitHub][github].

[hugo-docs]: https://gohugo.io/ "Hugo Docs"
[github]: https://github.com/ "GitHub"

Rendering Effect:

This is Hugo Documentation, this is GitHub.

Syntax: [Jump Text](#Title Text) (Title text needs to be lowercase, space replaced with -)

[Jump to First Level Title](#First Level Title)
[Jump to List Section](#4-List Ordered Unordered Nested)

Rendering Effect: Clicking jumps to the corresponding title position on the page (Hugo automatically generates anchors).

Image (Inline/Reference)

Syntax: ![Alt Text](Image Address "Optional Title") (Alt text is displayed when image fails to load)

# Inline Image (Network Image)
![Hugo -logo](https://gohugo.io/images/hugo-logo-wide.svg "Hugo Official Logo")

# Inline Image (Local Image, Hugo needs to be placed in the static directory)
![Local Image Example](./images/photo.jpg "Local Image")

# Reference Image (Reusing Address)
![GitHub Logo][github-logo]
[github-logo]: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png

Rendering Effect: Displays images, hover shows titles, alt text is displayed when loading fails.

Citation (Block Citation)

Syntax: > + space (supports nesting, multiple >)

> This is a first-level citation (single arrow)
> Citation content can be line-breaked, just add > at the beginning of each line.
>> This is a second-level citation (double arrow, nested)
>>> This is a third-level citation (triple arrow)
>
> Citation can include other syntax:
> - Unordered list
> **Bold text**

Rendering Effect:

This is a first-level citation (single arrow)
Citation content can be line-breaked, just add > at the beginning of each line.

This is a second-level citation (double arrow, nested)

This is a third-level citation (triple arrow)

Citation can include other syntax:

  • Unordered list
    Bold text

Code (Inline/Code Block)

Inline Code

Syntax: `Code Content` (backticks wrapped)

Inline code example: `print("Hello Markdown")`, `const x = 10`

Rendering Effect: Inline code example: print("Hello Markdown"), const x = 10

Code Block (Supports Syntax Highlighting)

Syntax: + Language Identifier (e.g. python, javascript), end with

```go
// Go language code block (combined with Hugo highlighting)
package main
import "fmt"
func main() {
    fmt.Println("Hello Code Block!")
}
Rendering Effect: Syntax-highlighted code block (needs to be combined with Chroma CSS).

#### Separator
Syntax: `---`/`***`/`___` (single line, blank lines before and after, three have the same effect)
```markdown
Text above the separator
---
Text in the middle of the separator
***
Text below the separator
___

Extended Syntax (Hugo Compatible)

Table (Supports Alignment)

Syntax: | separates columns, second line uses : to control alignment (:--- left-aligned, ---: right-aligned, :---: centered)

| Name   | Age | Score  |
|--------|-----|--------|
| Zhang San | 18 | 92.5 |
| Li Si | 19 | 88.0 |
| Wang Wu | 18 | 95.0 |

# Aligned Table
| Left-aligned | Right-aligned | Centered |
|:------------|--------------:|:---------:|
| Text1       | Number1       | Content1  |
| Text2       | Number2       | Content2  |

Rendering Effect:

NameAgeScore
Zhang San1892.5
Li Si1988.0
Wang Wu1895.0
Left-alignedRight-alignedCentered
Text1Number1Content1
Text2Number2Content2

Task List (Checkbox)

Syntax: - [ ] Not completed / - [x] Completed ([ ] needs to have a space, x is case-insensitive)

- [x] Complete Markdown syntax learning
- [x] Write code snippets
- [ ] Publish Hugo blog
- [ ] Optimize website style

Rendering Effect:

  • Complete Markdown syntax learning
  • Write code snippets
  • Publish Hugo blog
  • Optimize website style

Footnote (Annotation)

Syntax: [^Footnote Identifier] defines a reference, at the bottom of the page use [^Footnote Identifier]: Footnote content to define explanation

This is text that needs annotation[^1], this is another annotation[^note].

[^1]: This is detailed explanation of the first footnote (supports line breaks and links: [Hugo](https://gohugo.io))
[^note]: This is the explanation of the second footnote, identifiers can be letters or numbers

Rendering Effect:

This is text that needs annotation1, this is another annotation2.

Definition List (Term + Explanation)

Syntax: “Term” on a separate line, next line use “:” + space for explanation (supports nesting)

Markdown
: A lightweight markup language for quickly writing documents
: Compatible with most blog platforms and static site generators (such as Hugo)

Hugo
: Static site generator
    - Developed in Go language
    - Fast rendering speed
    - Built-in code highlighting

Rendering Effect:

Markdown
A lightweight markup language for quickly writing documents
Compatible with most blog platforms and static site generators (such as Hugo)
Hugo
Static site generator
  • Developed in Go language
  • Fast rendering speed
  • Built-in code highlighting

Escaping Characters (Avoid Syntax Conflicts)

When you need to display Markdown syntax symbols (such as #, *, [, etc.), use \ to escape:

  • This is not italic (asterisk escaped)
    Link text (square brackets escaped, displays original text)

  1. This is detailed explanation of the first footnote (supports line breaks and links: Hugo↩︎

  2. This is the explanation of the second footnote, identifiers can be letters or numbers ↩︎