This commit is contained in:
nora 2022-07-21 17:28:52 +02:00
parent fd248a8c1a
commit eab339d869
8 changed files with 0 additions and 129 deletions

3
404.md
View file

@ -1,3 +0,0 @@
# i did not find what you asked for
have you considered learning how to type?

View file

@ -1,3 +0,0 @@
# nilstrieb.github.io
hi

View file

@ -1 +0,0 @@
theme: jekyll-theme-cayman

View file

@ -1,9 +0,0 @@
true
ref ref ref
ptr ptr ptr
ptr ref ptr
mut

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

View file

@ -1,8 +0,0 @@
# cool blog
yeah it's literally a really cool blog you should totally read it
![img.png](ferrisclueless.png)
hi
* [types](types-rust-ts-java)

View file

@ -1,96 +0,0 @@
# Types in Rust, Typescript and Java
I find programming languages very interesting, but what I find even more interesting is comparing them
and seeing their similarities and differences. So let's do that!
## Employees
Say you want to build an employee management program. You could model the employees like this:
```java
public class Employee {
public String name;
public int number;
}
```
> But using public fields in Java is bad practice?
Go away, I don't care.
```ts
type Employee = {
name: string;
number: number;
}
```
```rust
struct Employee {
pub name: String,
pub number: i32,
}
```
They look very similar, don't they? Sure, the syntax differs a bit and Typescript only allows floats (yikes) but they
feel like they are the same.
Now we crate a function to print their names.
```java
public class Employee {
public static void printName(Employee employee) {
System.out.println(employee.name);
}
}
```
> Why is the method static???
Because I decided so.
```ts
const printName = (employee: Employee) => {
console.log(employee.name)
};
```
```rust
fn print_name(employee: Employee) {
println!("{}", employee.name);
}
```
Still nothing special. Time to call it!
```java
Employee.printName(new Employee("nils", 1));
```
> Assuming we have ~~written~~ auto-generated a constructor
```ts
printName({ name: 'nils', number: 1 })
```
```rust
print_name(Employee { name: "nils".to_owned(), number: 1 })
```
> What are you doing with the `to_owned` on the string?
Rust strings are complicated.
Hmm, this is interesting. There is one big difference among the three calls: `{ name: 'nils', number: 1 }`.
The Typescript code is not saying that its creating an `Employee`, it's just creating some object. What does that mean?
## Structural Typing
That's because Typescript uses structural typing. To quote wikipedia:
> A structural type system is a major class of type systems in which type compatibility and
> equivalence are determined by the type's actual structure or definition and not by
> other characteristics such as its name or place of declaration.
Structural typing means that the type checker only looks at the structure of the types to see whether they match, instead
of looking at the names (how Java and Rust do it).

View file

@ -1,9 +0,0 @@
## cool and fun blog
i love how cool it is
read [this](cool-blog)
### Jekyll Themes
Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/Nilstrieb/nilstrieb.github.io/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file.