feat: link to file in footer
This commit is contained in:
parent
7d8e959db5
commit
0f4cd3ca20
|
@ -1,65 +0,0 @@
|
||||||
---
|
|
||||||
title: Writing code considered harmful
|
|
||||||
date: 2023-06-14T22:09:06.127Z
|
|
||||||
---
|
|
||||||
|
|
||||||
When I initially delved into programming, I held the belief that it revolved solely around composing sets of instructions for the computer to execute. At a glance, it indeed appeared as such - merely commanding the computer to carry out tasks in a predetermined sequence, with the anticipation of obtaining a desirable outcome. This perception was further reinforced when observing how computers interpret code in assembly language, where each step is executed in a specific order within the CPU.
|
|
||||||
|
|
||||||
However, my view gradually changed as I was studying computer science at an university. First it was the object-oriented programming, which showed me the importance of choosing the right high level abstractions for a given problem. It started to seem to me as if programming was more about composing such abstractions to make problems easier to solve and easier to modify as needs change :cite[gamma1994design].
|
|
||||||
|
|
||||||
I also once thought that mathematics are not that important when it comes to computer science. I remember that at the start I had linear algebra and calculus courses, but I didn't really enjoy them much. Back then I didn't really understand the value of mathematics in this context, I just thought that they were things I had to pass on the way to „real” programming. To my horror it never seemed to end! It just became more subtly embedded within what I was doing all around.
|
|
||||||
|
|
||||||
For instance, statistics, and linear algebra, turned out to be the key to understanding machine learning. Without sufficient knowledge in that area of mathematics you can't really grasp how machine learning works on the fundamental level :cite[chollet2021deep]. It was at that point that I regretted not having worked harder at my linear algebra foundations.
|
|
||||||
|
|
||||||
A highlight of my studies was when I had a functional programming course, which felt like a U-turn probably on everything I learned up until that point. Suddenly, mutability was a bad thing, and everything was a function. I had to give up living in the object-oriented world. At that point I realized that there is in fact a different way to write software, and it's one deeply connected with nothing other than - mathematics. Okay.
|
|
||||||
|
|
||||||
Functional programming has the additional advantage over imperative and object-oriented paradigms that its abstractions are founded in mathematics. In fact, you can even write your programs using denotational demantics, which essentially means that code is more or less equivalent to mathematical equations. You can prove the program is correct by proving that the mathematical equivalent of it is :cite[10.1145/360303.360308].
|
|
||||||
|
|
||||||
It's really powerful.
|
|
||||||
|
|
||||||
## Summary
|
|
||||||
|
|
||||||
It was a pretty fun and interesting adventure, difficult at times, but worth it over all. In hindsight, I regret not paying more attention to mathematics right from the start. If I were to start over I would probably focus more on that and the theory of computation. If you're only just starting out then please remember, writing code is not computer science :cat:
|
|
||||||
|
|
||||||
|
|
||||||
## Bibliography
|
|
||||||
|
|
||||||
:::bibtex
|
|
||||||
@book{gamma1994design,
|
|
||||||
title = {Design Patterns: Elements of Reusable Object-Oriented Software},
|
|
||||||
author = {Gamma, E. and Helm, R. and Johnson, R. and Vlissides, J.},
|
|
||||||
isbn = {9780321700698},
|
|
||||||
lccn = {94034264},
|
|
||||||
series = {Addison-Wesley Professional Computing Series},
|
|
||||||
year = {1994},
|
|
||||||
publisher = {Pearson Education}
|
|
||||||
}
|
|
||||||
|
|
||||||
@book{chollet2021deep,
|
|
||||||
title = {Deep Learning with Python, Second Edition},
|
|
||||||
author = {Chollet, F.},
|
|
||||||
isbn = {9781617296864},
|
|
||||||
lccn = {2021425412},
|
|
||||||
year = {2021},
|
|
||||||
publisher = {Manning}
|
|
||||||
}
|
|
||||||
|
|
||||||
@article{10.1145/360303.360308,
|
|
||||||
author = {Tennent, R. D.},
|
|
||||||
title = {The Denotational Semantics of Programming Languages},
|
|
||||||
year = {1976},
|
|
||||||
issue_date = {Aug. 1976},
|
|
||||||
publisher = {Association for Computing Machinery},
|
|
||||||
address = {New York, NY, USA},
|
|
||||||
volume = {19},
|
|
||||||
number = {8},
|
|
||||||
issn = {0001-0782},
|
|
||||||
url = {https://doi.org/10.1145/360303.360308},
|
|
||||||
doi = {10.1145/360303.360308},
|
|
||||||
journal = {Commun. ACM},
|
|
||||||
month = {aug},
|
|
||||||
pages = {437–453},
|
|
||||||
numpages = {17},
|
|
||||||
keywords = {semantics, GEDANKEN, store, environment, LOOP, continuation, applicative, higher-order function, imperative, programming language, theory of computation, recursive definition}
|
|
||||||
}
|
|
||||||
:::
|
|
|
@ -137,7 +137,11 @@ fn to_source(path: Utf8PathBuf, exts: &HashSet<&'static str>) -> FileItem {
|
||||||
|
|
||||||
pub fn render_all(items: &[Output]) {
|
pub fn render_all(items: &[Output]) {
|
||||||
for item in items {
|
for item in items {
|
||||||
render(item, &Sack::new(items, &item.path));
|
let file = match &item.kind {
|
||||||
|
OutputKind::Real(a) => Some(&a.meta.path),
|
||||||
|
OutputKind::Fake(_) => None,
|
||||||
|
};
|
||||||
|
render(item, &Sack::new(items, &item.path, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use camino::Utf8PathBuf;
|
use camino::{Utf8Path, Utf8PathBuf};
|
||||||
use hayagriva::Library;
|
use hayagriva::Library;
|
||||||
|
|
||||||
use crate::html::{Link, LinkDate, Linkable};
|
use crate::html::{Link, LinkDate, Linkable};
|
||||||
|
@ -41,11 +41,13 @@ pub struct Sack<'a> {
|
||||||
hole: &'a [Output],
|
hole: &'a [Output],
|
||||||
/// Current path for page
|
/// Current path for page
|
||||||
path: &'a Utf8PathBuf,
|
path: &'a Utf8PathBuf,
|
||||||
|
/// Original file location
|
||||||
|
file: Option<&'a Utf8PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Sack<'a> {
|
impl<'a> Sack<'a> {
|
||||||
pub fn new(hole: &'a [Output], path: &'a Utf8PathBuf) -> Self {
|
pub fn new(hole: &'a [Output], path: &'a Utf8PathBuf, file: Option<&'a Utf8PathBuf>) -> Self {
|
||||||
Self { hole, path }
|
Self { hole, path, file }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_links(&self, path: &str) -> Vec<LinkDate> {
|
pub fn get_links(&self, path: &str) -> Vec<LinkDate> {
|
||||||
|
@ -96,4 +98,14 @@ impl<'a> Sack<'a> {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the path for output
|
||||||
|
pub fn get_path(&self) -> &'a Utf8Path {
|
||||||
|
self.path.as_path()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the path for original file location
|
||||||
|
pub fn get_file(&self) -> Option<&'a Utf8Path> {
|
||||||
|
self.file.map(Utf8PathBuf::as_ref)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use camino::Utf8Path;
|
||||||
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
|
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
|
||||||
|
|
||||||
use crate::REPO;
|
use crate::REPO;
|
||||||
|
@ -81,11 +82,15 @@ pub fn navbar() -> impl Renderable {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn footer() -> impl Renderable {
|
pub fn footer(path: Option<&Utf8Path>) -> impl Renderable {
|
||||||
let copy = format!("Copyright © {} Maciej Jur", &REPO.year);
|
let copy = format!("Copyright © {} Maciej Jur", &REPO.year);
|
||||||
let mail = "maciej@kamoshi.org";
|
let mail = "maciej@kamoshi.org";
|
||||||
let href = format!("mailto:{}", mail);
|
let href = format!("mailto:{}", mail);
|
||||||
let repo = format!("{}/tree/{}", &REPO.link, &REPO.hash);
|
let link = Utf8Path::new(&REPO.link).join("tree").join(&REPO.hash);
|
||||||
|
let link = match path {
|
||||||
|
Some(path) => link.join(path),
|
||||||
|
None => link,
|
||||||
|
};
|
||||||
|
|
||||||
maud_move!(
|
maud_move!(
|
||||||
footer .footer {
|
footer .footer {
|
||||||
|
@ -98,7 +103,7 @@ pub fn footer() -> impl Renderable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
div .repo {
|
div .repo {
|
||||||
a href=(repo) {
|
a href=(link.as_str()) {
|
||||||
(&REPO.hash)
|
(&REPO.hash)
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
|
|
|
@ -73,5 +73,5 @@ pub fn home<'data, 'home, R>(main: R) -> impl Renderable + 'home
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
page("Home", main)
|
page("Home", main, None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn list<'data, 'list>(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
page(title, list)
|
page(title, list, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn section(year: i32, group: &[LinkDate]) -> impl Renderable + '_ {
|
fn section(year: i32, group: &[LinkDate]) -> impl Renderable + '_ {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use camino::Utf8Path;
|
||||||
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
||||||
use crate::html::base::{head, navbar, footer};
|
use crate::html::base::{head, navbar, footer};
|
||||||
|
|
||||||
|
@ -19,10 +20,14 @@ pub fn bare<'data, 'html, R>(title: &'data str, main: R) -> impl Renderable + 'h
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn page<'data, 'main, 'page, T>(title: &'data str, main: T) -> impl Renderable + 'page
|
pub fn page<'data, 'main, 'html, T>(
|
||||||
|
title: &'data str,
|
||||||
|
main: T,
|
||||||
|
path: Option<&'data Utf8Path>,
|
||||||
|
) -> impl Renderable + 'html
|
||||||
where
|
where
|
||||||
'main : 'page,
|
'main : 'html,
|
||||||
'data : 'page,
|
'data : 'html,
|
||||||
T: Renderable + 'main
|
T: Renderable + 'main
|
||||||
{
|
{
|
||||||
maud_move!(
|
maud_move!(
|
||||||
|
@ -33,7 +38,7 @@ pub fn page<'data, 'main, 'page, T>(title: &'data str, main: T) -> impl Renderab
|
||||||
body {
|
body {
|
||||||
(navbar())
|
(navbar())
|
||||||
(main)
|
(main)
|
||||||
(footer())
|
(footer(path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
|
||||||
|
|
||||||
|
use crate::gen::Sack;
|
||||||
use crate::html::misc::{show_bibliography, show_outline};
|
use crate::html::misc::{show_bibliography, show_outline};
|
||||||
use crate::html::page;
|
use crate::html::page;
|
||||||
use crate::md::Post;
|
use crate::md::Post;
|
||||||
use crate::text::md::Outline;
|
use crate::text::md::Outline;
|
||||||
|
|
||||||
|
|
||||||
pub fn post<'fm, 'md, 'post, T>(
|
pub fn post<'f, 'm, 's, 'html, T>(
|
||||||
fm: &'fm Post,
|
fm: &'f Post,
|
||||||
content: T,
|
content: T,
|
||||||
outline: Outline,
|
outline: Outline,
|
||||||
bib: Option<Vec<String>>,
|
bib: Option<Vec<String>>,
|
||||||
) -> impl Renderable + 'post
|
sack: &'s Sack,
|
||||||
|
) -> impl Renderable + 'html
|
||||||
where
|
where
|
||||||
'fm: 'post,
|
'f: 'html,
|
||||||
'md: 'post,
|
'm: 'html,
|
||||||
T: Renderable + 'md
|
's: 'html,
|
||||||
|
T: Renderable + 'm
|
||||||
{
|
{
|
||||||
let main = maud_move!(
|
let main = maud_move!(
|
||||||
main .wiki-main {
|
main .wiki-main {
|
||||||
|
@ -46,5 +49,5 @@ pub fn post<'fm, 'md, 'post, T>(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
page(&fm.title, main)
|
page(&fm.title, main, sack.get_file())
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn map() -> impl Renderable {
|
||||||
(Raw("import 'photos';"))
|
(Raw("import 'photos';"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
))
|
), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search() -> impl Renderable {
|
pub fn search() -> impl Renderable {
|
||||||
|
@ -20,5 +20,5 @@ pub fn search() -> impl Renderable {
|
||||||
main {
|
main {
|
||||||
|
|
||||||
}
|
}
|
||||||
))
|
), None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,5 @@ pub fn wiki<'data, 'html, 'sack, T>(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
page(&fm.title, main)
|
page(&fm.title, main, sack.get_file())
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl Content for md::Post {
|
||||||
&'f self,
|
&'f self,
|
||||||
content: T,
|
content: T,
|
||||||
outline: Outline,
|
outline: Outline,
|
||||||
_: &'s Sack,
|
sack: &'s Sack,
|
||||||
bib: Option<Vec<String>>,
|
bib: Option<Vec<String>>,
|
||||||
) -> impl Renderable + 'html
|
) -> impl Renderable + 'html
|
||||||
where
|
where
|
||||||
|
@ -65,7 +65,7 @@ impl Content for md::Post {
|
||||||
'm: 'html,
|
'm: 'html,
|
||||||
's: 'html,
|
's: 'html,
|
||||||
T: Renderable + 'm {
|
T: Renderable + 'm {
|
||||||
html::post(self, content, outline, bib)
|
html::post(self, content, outline, bib, sack)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
|
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
|
||||||
|
|
Loading…
Reference in a new issue