Functional Design in Clojure - 第001集:为什么,到底为什么? 封面

第001集:为什么,到底为什么?

Episode 001: Why, Oh Why?

本集简介

内特和克里斯托弗试图弄清楚如何制作一档播客。 我们是谁? 我们在做什么? 我们要聊些什么? 大量(与元数据播客相关的...) 本期节目中的Clojure代码: nil

双语字幕

仅展示文本字幕,不包含中文音频;想边听边看,请使用 Bayt 播客 App。

Speaker 0

欢迎收听Closure设计播客。

Welcome to the Closure Design Podcast.

Speaker 0

我们将以Closure语言为例,解析函数式编程和问题解决的原则与技巧。

We're here to break down the principles and techniques of functional programming and problem solving using Closure as our language of choice.

Speaker 0

我是克里斯托弗·纽曼。

I'm Christophe Newman.

Speaker 1

我是内特·琼斯。

And I'm Nate Jones.

Speaker 1

每周我们会讨论Clojure开发日常工作中遇到的问题或设计难题。

Each week, we'll discuss a problem or design quandary we've encountered in our day to day work as Clojure developers.

Speaker 1

这周我们没有具体问题。

This week, we don't have a problem.

Speaker 1

我们想聊聊为什么要做这个播客。

We want to talk about why we're doing this podcast.

Speaker 1

不如我们先简单介绍一下各自的背景?

So why don't we start off by giving us giving a little bit of description about our background.

Speaker 1

克里斯托弗?

Christophe?

Speaker 0

好的。

Yeah.

Speaker 0

我从事编程很多年了。

I've been a programmer for a long time, many years.

Speaker 0

最初从Basic、Pascal、C这些古老语言起步,后来陆续学了Perl、Ruby、JavaScript、C++甚至PHP。

Started off with basic programming, Pascal, C, all this stuff way back in the day and went on to learn Pearl and Ruby and JavaScript and C plus plus and even PHP.

Speaker 0

在这个过程中,我变得很擅长学习新编程语言。

And in that time, I got pretty good at learning new programming languages.

Speaker 0

你知道的,最开始学的几门语言总是最难的。

You know, first couple languages were the hardest.

Speaker 0

然后我就想,哦,是时候学一门新语言了。

And after that, I I'd go, oh, time to learn a new language.

Speaker 0

让我们深入语法,弄清楚如何让编译器运行起来。

Let's dive into the syntax and let's figure out how to get the compiler going.

Speaker 0

它们看起来越来越容易上手。

And they just seemed like they got easier and easier to pick up.

Speaker 0

接着我遇到了函数式编程。

And and then I hit functional programming.

Speaker 0

这确实不一样。

It was it was different.

Speaker 0

在此之前,学习更多是关于掌握语法。

Before I it was really more of a learning a syntax thing.

Speaker 0

更多是学习特定语言的功能特性。

It was really more of a learning specific language feature thing.

Speaker 0

而函数式编程对我来说不同,因为多年来第一次,我在尝试解决问题时真的卡住了。

And then functional programming was different for me because now for the first time in years, I got stuck actually trying to solve problems.

Speaker 0

我脑子里有以前的解决方案,但我就是没法用它们。

I had these solutions in my brain from before I just couldn't use them.

Speaker 0

就像规则已经改变了。

Like the rules had changed.

Speaker 1

是啊,我完全同意。

Yeah, I totally agree.

Speaker 1

我也有很长一段时间使用面向对象语言的经验。

So I also have quite a history of working with object oriented languages.

Speaker 1

我的第一门是PHP。

My first one was PHP.

Speaker 1

这些年我做过很多Java和Perl,主要是面向对象的,甚至还有Python。

I did a lot of Java and a lot of Perl over the years, mostly object oriented, Python even.

Speaker 1

真有趣,你说我提到了PHP。

Funny you said I mentioned PHP.

Speaker 1

感觉每个人都曾在PHP里兜过一圈。

Think everyone's done a tour in PHP.

Speaker 0

对,兜一圈。

Right, a tour.

Speaker 0

就像服役一样兜一圈。

A tour of duty.

Speaker 1

是啊。

Yeah.

Speaker 1

我知道软件开发需要持续学习,所以每年都把学习新事物当作挑战。看到你在函数式编程甚至Clojure本身遇到的困境后,我对转换范式产生了兴趣——从面向对象转向函数式。Clojure似乎是锻炼思维的好选择,我学了很多,但突然撞上南墙:语法我能懂,可怎么突破到构建大型系统呢?

And I've known that in software development you have to continually learn and so I kind of took it as a challenge every year to learn something new and I kind of had seen you struggling with functional programming and then also to some degree with Clojure itself, and so I grew interested in the idea of changing the paradigm that I work in away from object oriented and it's functional, and so Clojure seemed like it would be a good thing to challenge my mind, and so I learned a lot of it, but then I ran smack into the I can understand the syntax, but how do I move past that into larger systems?

Speaker 0

确实。

Right.

Speaker 0

我们之前总在摆弄些圆锥体之类的玩具问题,就像你说的。但要转型到解决现实问题的系统,而不是只搞些编程竞赛的小题目,比如Advent of Code那种。

There there is playing around with like cones and and and things like that and and really the the toy problems like you said, but then trying to translate into something bigger, trying trying to get into a system that did real world things and didn't just, you know, figure out some fun little programming contest problem, you know, as part of Advent of Code or something.

Speaker 0

你我编程多年,这次却真的卡住了——这是很久没有过的深度卡壳。

And so, you and I have both been programming for years and years, and here we are getting stuck, really getting stuck for the first time in a long time.

Speaker 0

这确实需要全新的思维方式。

And it required like a new way of thinking really.

Speaker 0

所以这就是我们想做这档播客的原因。

And so that's why we wanted to start this podcast.

Speaker 0

我们钻研函数式编程已有数年。

We have now been at this for several years of functional programming.

Speaker 0

不是说我们找到了所有答案,但确实跨过了许多障碍,现在能分享些心得了。

And I'm not saying that we got the answers, but we've gotten on the other side of a lot of these hurdles and we're able to share something.

Speaker 1

没错。

Yeah.

Speaker 1

我是说,函数式编程本身就是一个不同的概念,需要花时间去理解。

I mean, so functional programming by itself is a different concept, a different thing to wrap your head around.

Speaker 1

Clojure以其特有的括号著称,但实际设计时结合这两者确实各有各的难点。

Clojure has its own with all the parentheses as they say, but then actually trying to design something with those two things all difficulties in their own right.

Speaker 1

这些都是你会遇到的挑战,我们也曾为此挣扎过。

They're all things that you would struggle with and we have struggled with.

Speaker 1

所以很多时候功能强大的东西往往也非常复杂。

And so something that's powerful a lot of times ends up being very complex.

Speaker 1

我认为我们发现的是,函数式编程尤其是Clojure,确实让我们能够设计出不仅更简单、复杂度更低、更易理解(从而更易维护)的软件,而且附带的好处是,用它工作起来也更有乐趣。

And I think what we've found is that functional programming and Clojure specifically have really been able to allow us to make designs, to design software that is not only simpler, like it's less complex, it's easier to understand, which makes it more maintainable, but also as a kind of a side effect, it's a lot more fun to work with.

Speaker 0

确实,当你熬过卡壳的挫败感后——可能你听着完全无法感同身受——

Yeah, it definitely, after you get over the frustration of being stuck, you know, maybe you're listening to this and you don't relate to that at all.

Speaker 0

这就像是一个自然而然的转变。

It was just like a natural transition.

Speaker 0

如果是这种情况,我们很乐意听听你的经历。

We would love to hear from you if that is the case.

Speaker 0

但对我来说,当我熬过卡壳的挫败期,开始觉得自己掌握了函数式编程的要领,能在合理时间内取得进展时,它确实变得很有趣,因为这门语言的特性实在太棒了。

But for me, after I got over the frustration of being stuck and I started to feel like I had gotten my functional programming legs on and I could actually make some progress in a reasonable amount of time, it really did become quite fun because the properties of the language were so nice.

Speaker 0

比如能够隔离某些副作用,避免面向对象编程中常见的那些挫败感。

Like being able to isolate some of these side effects, not have these frustrations that happened in OO.

Speaker 0

所以它确实变得有趣,这也是我们坚持使用它的真正原因。

And so that did become fun and that's really why we stuck with it.

Speaker 1

是啊。

Yeah.

Speaker 1

我记得刚开始接触函数式编程和Clojure时,还是个业余爱好者。

So I remember back when I was first getting into the functional and getting into closure, I was a hobbyist.

Speaker 1

我当时白天工作用的是Python,可以这么说。

I couldn't I was using Python during my day job, so to speak.

Speaker 1

我发现可以将函数式编程技巧应用到Python中,这样能更好地理解问题,或者让代码比处理模拟对象的世界更具可测试性。

And I found that I could apply functional techniques to Python programming and really be able to understand things better or make things way more testable than dealing with the world of mocks as it were.

Speaker 0

哦,模拟对象。

Oh, mocks.

Speaker 0

没错,模拟对象。

Yes, mocks.

Speaker 0

是的。

Yeah.

Speaker 1

函数式设计原则确实能帮你摆脱那种需要模拟半个系统只为避免少量IO操作的困境。

Functional design principles really help you get away from that whole realm of trying to mock up half your system just to avoid a little bit of IO.

Speaker 1

但后来我试图用一种非惯用的语言实现所有这些功能。

But then I was trying to do all these things in a language that for so to speak, it was not idiomatic.

Speaker 1

这不是Python应有的编程方式。

It wasn't the way things were supposed to be done in Python.

Speaker 0

确实。

Right.

Speaker 0

需要非常谨慎的编程。

Lots of careful programming.

Speaker 0

有点像JavaScript,让我想起这种语言允许你做太多事情。

Kinda like in JavaScript, it reminds me the language lets you do so many things.

Speaker 0

所以每个团队都有自己特殊的JavaScript写法,或是特殊的Perl写法,来管理语言允许你陷入的复杂性。

And so every team has their own special way of doing JavaScript or special way of doing Perl to manage the complexity that the language lets you get into.

Speaker 1

是啊,关于JavaScript有个经典笑话,就是关于它的糟糕部分和优秀部分,我们现在就可以插播这个梗。

Yeah, there's a whole joke about JavaScript, the slow part or the good parts that we might be able to insert here.

Speaker 0

没错。

Right.

Speaker 0

是的。

Yes.

Speaker 1

因此,在Clojure中做事的一个好处是,可以说它是一种语言,你做事情的方式就是这些函数式模式。

And so, one of the nice things about doing things in Clojure is that it's a language that, so to speak, the way you do things is these functional patterns.

Speaker 1

这样你就不必那么小心翼翼,因为这门语言天生就倾向于那种方式。

So then you don't have to be as careful because the language is naturally slanted that way.

Speaker 0

是啊。

Yeah.

Speaker 0

这门语言里有很多‘墙’。

Language has a lot of walls in it.

Speaker 0

就是那种墙,你知道的,像高速公路上的护栏?

The kind of walls, you know, like guardrails on the freeway?

Speaker 0

那些防止你冲下悬崖丧命的护栏,对吧?

The ones that keep you from going over the cliff and dying, right?

Speaker 0

以防你犯错的时候。

If in case you make a mistake.

Speaker 0

非常有用,这些保护屏障。

So so helpful, helpful barriers.

Speaker 0

所以,没错,这就是我们选择Clojure的原因。

And so, yeah, that's that's why we're choosing Clojure.

Speaker 0

我们之所以持续在Clojure上投入大量工作,是因为我们确实很喜欢这门语言的许多设计选择,而且它是一门纯函数式语言。

That's why we've continued to do a lot of work in Clojure is because we really do like a lot of the design choices in the language and it is a pure functional language.

Speaker 0

所以如果你真想进入函数式编程领域,它是个绝佳选择——因为你别无选择。

So it really, if you wanna get into functional programming, it's a wonderful language because you don't have a choice.

Speaker 0

如果你想用Clojure工作,你就得进行函数式编程。

If you wanna work in Clojure, you're gonna be doing functional programming.

Speaker 0

不像Scala、Python、Ruby等多范式语言,它们有通往面向对象的‘出口坡道’——那种舒适温馨的OO范式,可能会让你逃避直面这些问题。

As with multi paradigm languages like Scala or Python or Ruby or whatnot, there's this exit ramp into OO, comfortable, warm, cuddly OO that maybe maybe lets you avoid, you know, really staring down these problems.

Speaker 0

好的。

Okay.

Speaker 0

抛开语言批评不谈,这档播客的核心在于分享我们发现的这些原则、我们领悟到的事物、我们偏好的工作方式,特别是与Clojure相关的内容,并就此展开讨论。

But but language criticism aside, this podcast is really about us taking these principles we've discovered, things we've figured out, ways we like to do things, Clojure specific things and just talking about them.

Speaker 0

我们每周都会提出一个话题,然后两人将基于各自的经验进行探讨。

We're gonna bring up a topic every week and both of us are just gonna discuss it based on our experience.

Speaker 0

不过要知道,我们可能会一直聊下去,因为我们喜欢交谈,但我们更想听听你们的想法。

But this could be a You know, we could just go on forever because we like to talk, but we wanna hear from you.

Speaker 0

我们想知道你们对哪些话题感兴趣,希望我们讨论什么内容。

We wanna hear what topics you're interested in hearing about, what topics you would like discussed.

Speaker 0

当然,你们可以通过邮件联系我们,也一定要在Twitter上@我们。

Definitely, you know, send us email, hit us up on Twitter for sure.

Speaker 0

我们希望这能形成一个良性反馈循环。

Let's make this our hope is that this is a feedback loop.

Speaker 1

没错,确实如此。

Yeah, definitely.

Speaker 1

我是说,任何关于函数式编程的领域,特别是Clojure,或是设计大型复杂系统——就像Rich所说的情境化程序,那些需要与现实世界打交道的程序。

I mean, anything in the realm of functional programming at large, Clojure specifically, or designing large complex or as Rich calls them situated programs, you know, programs that have to deal with the real world.

Speaker 1

这些都是我们亲身经历后获得的经验。

Those are all lessons that we've learned.

Speaker 1

而且都是来之不易的经验。

They've been hard lessons.

Speaker 1

我们身上还留着在Clojure安全护栏上撞得头破血流的伤疤呢。

We have the scars to show where we have rammed our head against the nice guardrails in closure.

Speaker 1

但正因为如此,我们才真正找到了穿越迷雾的方法,所以想分享这些知识——当然我们也清楚自己并非无所不知。

But because of that, we've really been able to kind of find our way through them and so, you know, we want to share that knowledge but also of course we don't think we know everything.

Speaker 1

显然还有很多需要学习的地方,因此我们非常期待听到你们的见解。

There's definitely a lot more to be learned and so definitely we want to hear from you.

Speaker 0

是的,而且我们希望保持相对简短的周更形式。

Yes, and we wanna keep it relatively short and weekly.

Speaker 0

如果我们需要深入探讨,我们希望能听到你的反馈。

If we need to go into more depth, then we wanna hear from you.

Speaker 0

告诉我们,嘿,我们想要更多。

Tell us, hey, we want more.

Speaker 0

如果你希望更频繁更新,你知道的,请告诉我们。

If you want more frequency, you know, let us know.

Speaker 0

但我们的目标是每周发布,保持简短,讨论这些话题,听取你们的反馈,然后进行调整。

But our goal is to publish weekly and keep it short and then talk about those topics and hear back from you and then adapt.

Speaker 0

对我们来说,这个播客的关键之一是探讨设计上的权衡取舍。

But one of the key aspects of the podcast for us really is to get into the design trade offs.

Speaker 0

这个播客真的不是为了学习闭包之类的内容。

This podcast really isn't about like learning closure.

Speaker 0

它实际上也不是为了掌握那些基础知识。

It isn't really about like getting those basics.

Speaker 0

我认为市面上已有大量优秀资料可供学习语言和基础知识。

I think there's a lot of great material out there where you can learn the language and learn some of the basics.

Speaker 0

这个播客关注的是:好吧,我知道如何用这种语言进行计算,但如何构建系统?

This is about, okay, I know how to do computation in this language, but how do I make systems?

Speaker 0

如何用这种语言解决现实问题?

How do I solve real world problems in the language?

Speaker 1

是的。

Yeah.

Speaker 1

我认为需要考虑的重要一点是我们在播客中采用的讨论方式。

I think an important thing to think about is kind of the way that we're facing in this podcast.

Speaker 1

你看,我们不是在采访别人,而是真正试图剖析问题——我们邀请听众和我们一起凝视问题并展开讨论,因为很多问题不可能在十五分钟内解决。

You know, we're not interviewing people, we're really trying to take the problem and look at the problem, you know, we're gathering you next to us as we all stare at the problem and talk about it Because a lot of these problems are not going be solved in fifteen minutes.

Speaker 1

不会有什么干净利落的解决方案。

There's not going to be any neat and tidy things.

Speaker 1

要知道,好的设计或任何设计本质上都是关于权衡取舍的。

Know, good design or any design really is all about trade offs.

Speaker 1

关键在于描述每个解决方案的优缺点,然后根据你当前的具体情况决定哪个最合适。

It's about describing what the pros and cons are of each solution and then deciding which one of those is appropriate for the particular situation you're in.

Speaker 1

所以对我们来说,我们并非专家,也不是高高在上地发号施令,更像是一个支持小组或治疗会谈的镜子。

And so, to us to be this is not we're not experts, we're not, you know, sitting from on high and giving out things, we're more of a support group or a mirror of a therapy session, if you will.

Speaker 1

就像你可以悄悄来到酒吧,或是坐在折叠椅上,倾诉闭包如何折磨你,我们一起探讨如何改进它。

Place where you can go you know, sidle up to the bar or, you know, sit down in the folding chair and talk about how closure has beaten you up and we can talk about how we can make it better.

Speaker 0

是啊。

Yeah.

Speaker 0

如果你想找一群架构宇航员告诉你正确做法,发邮件给我们,我们可以推荐其他编程语言。

If you're looking for a group of architecture astronauts that will let you know the right way to do things, send us an email and we can recommend some other programming languages for you.

Speaker 0

如果你好这口,外面有些很棒的播客。

There's some excellent podcasts out there if that is what you are into.

Speaker 0

在这里我们只想分享经验,希望对你有所帮助,告诉你我们如何用Clojure函数式编程完成些很酷的事。

Here we wanna just basically share our experience and hope you benefit from it and let you know how we've been able to get some really neat things done in functional programming in Clojure.

Speaker 1

酷。

Cool.

Speaker 1

我想我们今天聊的内容差不多够了。

I think so I think we're getting close to having enough stuff to talk about today.

Speaker 0

是啊。

Yeah.

Speaker 0

今天就到这里吧,下期节目我们直接切入正题。

I think let's wrap it up for today and we'll just get right into it in our next episode.

Speaker 0

非常感谢收听,期待你继续关注下期节目。

Thank you so much for listening to this and we hope that you tune in for our next episode.

Speaker 0

你可以查看我们的节目笔记和往期内容。

You can find our show notes and our past episodes.

Speaker 0

哦,等等。

Oh, wait.

Speaker 0

我们没有往期节目。

We have no past episodes.

Speaker 0

但如果你在未来听到这段话,我们就会有往期节目了。

But if you hear this in the future, we will have past episodes.

Speaker 0

你可以在closuredesign找到所有节目。

So you can find all the episodes at closuredesign.

Speaker 0

俱乐部。

Club.

Speaker 0

你也可以在Twitter上通过closuredesign联系我们。

And you can also hit us up on Twitter at closuredesign.

Speaker 1

我们的邮箱是feedback@closuredesign.club。

Our email is feedback@closuredesign.club.

Speaker 1

请把你的问题和反馈发给我们。

Please send us your questions and feedback.

Speaker 1

我们很乐意听取你的意见。

We'd love to hear from you.

Speaker 0

是的。

Yes.

Speaker 0

我们非常重视你的反馈,尤其是在我们刚起步的阶段。

We definitely value your feedback, especially since we're getting this going.

Speaker 0

下次见面之前,注意安全,避免副作用。

And until we talk to you next time, stay safe and avoid side effects.

关于 Bayt 播客

Bayt 提供中文+原文双语音频和字幕,帮助你打破语言障碍,轻松听懂全球优质播客。

继续浏览更多播客