简体   繁体   English

应用功能编程

[英]Functional programming applied

I have been interested in programming all my life and for the past 6 years I have worked almost exclusively with Java. 我一生都对编程感兴趣,在过去的6年中,我几乎只使用Java。 I just finished with my University studies and have a job as a Java developer for a company. 我刚完成大学学习,然后就职于一家公司的Java开发人员。

All these years programming has been a hobby and a favorite past time, but this had a slightly negative effect in the sense that i grew so accustomed to Java i never ventured beyond it as a programming language. 这些年来,编程一直是一种爱好,是过去的最爱,但这在某种程度上产生了负面影响,因为我对Java习以为常,因此我从来没有冒险将Java作为编程语言。 I did try to expand my knowledge of things by learning regular expressions, SQL and studied a bit of XML but i could never get involved enough with a new language to learn how to use it properly party because they all look alike so much at their core, i found the learning curve of every new language irritating. 我确实尝试通过学习正则表达式,SQL来扩展我对事物的知识,并研究了一些XML,但是我永远也不会参与一种新语言来学习如何正确地使用它,因为它们在本质上看起来非常相似,我发现每种新语言的学习曲线都很令人讨厌。 I felt like i had to go through the whole process to end up right were i started as i felt that other imperative languages had nothing more to offer me (i know this statement can start a fight, it is not my intention). 我觉得我必须经历整个过程才能正确开始,因为我觉得其他命令式语言无济于事(我知道这句话可以打架,这不是我的意图)。

I therefore decided at one point to explore the magical world of functional programming. 因此,我决定一次探索函数式编程的神奇世界。 I begun reading a book on Haskel and found it really interesting from an academic point of view (i majored in Mathematics) but could not find practical applications of it to get me going enough to learn the language. 我开始阅读有关Haskel的书,从学术角度(我主修数学)发现它真的很有趣,但是找不到它的实际应用来使我足够学习该语言。

So now that Java is the main part of my day since i am getting paid to code in it (and i enjoy it as much as i did when it was simply a hobby) i felt the need again to broaden my horizons and again functional programming seems like a good idea. 因此,既然Java是我日常工作的主要部分,因为我从中获得使用代码的报酬(而且我像在业余爱好中一样享受它,所以我会像以前一样享受它)我感到有必要再次拓宽视野并再次进行函数式编程似乎是个好主意。

I thought i would start with Scala since i am Java literate (make the transition easier and be more reusable since they can "talk" to each other) and so my question is : In your experience does learning a functional language "make sense"? 我以为我会讲Java,所以我会从Scala开始(由于他们可以彼此“交谈”,因此使过渡更容易并且更可重用),所以我的问题是: 根据您的经验,学习功能语言是否“有意义”? Are there any real life applications where knowing this paradigm may come in handy? 在现实生活中,有什么应用程序可以使这种范例变得有用吗? Not only for personal entertainment but also would this be a "pro" in the industry? 不仅用于个人娱乐,而且这将成为行业中的“专业人士”吗?

In my opinion learning functional programming it is not only a good idea because it makes you a better programmer (think which I agree, of course) but because it seems it will become very popular in a near future. 在我看来,学习函数式编程不仅是一个好主意,因为它可以使您成为更好的程序员(当然,我同意),还因为它似乎在不久的将来会变得非常流行。

A lot "gurus" are saying that it will be the only way to keep Moore's law alive. 很多“专家”都说这将是保持摩尔定律不变的唯一方法。 Computer clock speed has reach a top and the only way to improve processors speed will be adding more and more cores. 计算机时钟速度已达到顶峰,提高处理器速度的唯一方法是增加越来越多的内核。 In this scenario functional programing becomes handy because in those languages data is immutable and that makes them very easy to paralelize (it can be done automatically actually). 在这种情况下,函数式编程变得很方便,因为在那些语言中,数据是不可变的,这使得它们非常易于并行化(实际上可以自动完成)。

You might want to have a look to the next references 您可能想看看下一个参考资料

Buff, I hope it wasn't too bored, ;-) Buff,我希望它不会太无聊,;-)

Learning a functional language is a big plus, regardless of whether or not you ever use it in your day job. 无论您是否在日常工作中使用功能语言,学习功能语言都是一大优势。 Consider the following: 考虑以下:

  1. One of the biggest recommendations for successful concurrent programming is to avoid mutable state in your threaded objects whenever possible. 成功进行并发编程的最大建议之一是尽可能避免线程对象中的可变状态。 Functional programming teaches you how to do this. 函数式编程教您如何做到这一点。
  2. Most functional programmers, once they get over the not-insubstantial learning curve, claim that their techniques make them far more productive than they can be in standard imperative languages. 大多数函数式程序员一旦克服了非实质性的学习难题,就声称他们的技术使他们的生产力大大超过标准命令式语言。 Their code is more bug-free, and a fraction of the size as that of other languages. 他们的代码更加没有错误,并且大小仅为其他语言的一小部分。 Think of the productivity boost you got when you finally understood regular expressions. 想一想当您终于了解了正则表达式后,您可以提高工作效率。 Now put that on steroids. 现在把它放在类固醇上。 That's what FP can feel like. 就是FP的感觉。
  3. Functional techniques are rapidly making their way into imperative programming. 功能技术正在迅速进入命令式编程。 Think closures in C#, and Javascript, and soon (maybe, if we're lucky) in Java. 考虑一下C#和Javascript中的闭包,以及不久之后(也许是幸运的话)使用Java。 It's very likely the two worlds will soon come together. 这两个世界很可能很快会聚在一起。
  4. Finally, in job interviews, knowing a functional language will help you stand out from your average J2EE/.NET clone. 最后,在工作面试中,了解一种功能语言将帮助您在普通的J2EE / .NET克隆产品中脱颖而出。 It marks you as a self-starter, a disciplined learner, and a passionate programmer -- whether or not you actually are any of these things. 它标志着您是一个自我入门者,一个训练有素的学习者以及一个热情的程序员-无论您实际上是不是这些人中的任何一个。 Just don't become yet another slathering Scala fanboy, scolding your soon-to-be boss about how he's missing out on the best programming techniques since... you get the idea. 只是不要再成为另一个臭名昭著的Scala狂热粉丝,责骂您即将成为老板的人,因为自从您了解这个想法以来,他是如何错过最佳编程技术的。 It's never good to insult a prospective employer. 侮辱准雇主永远都不是好事。

For me, studying Haskell has made programming a lot more fun than it used to be. 对我来说,学习Haskell使编程变得比以往更加有趣。 It may do the same for you as well. 它也可能为您做同样的事情。 Good luck! 祝好运!

Functional programming has been making inroads in the financial sector. 函数式编程已在金融领域取得了进展。 Which isn't really all that much surprising, if you consider financial analysts have been "programming" in Excel for years, and that's essentially a functional paradigm (more precisely, functional reactive). 如果您认为财务分析师多年来一直在Excel中进行“编程”,那么这并不是真的那么令人惊讶,这本质上是一种功能范式(更确切地说,是功能响应式)。

So, yes, knowing functional programming can open a few doors just OO can't, and such jobs can be very interesting. 因此,是的,了解函数式编程可以打开一些OO不能打开的门,而这样的工作可能会非常有趣。

Speaking strictly as a Java programmer, you'll learn techniques you can employ in Java in your day-to-day (though you'll want a better Collections library). 严格来讲,作为Java程序员,您将学习可以在Java中日常使用的技术(尽管您需要更好的Collections库)。 Techniques which will decrease the amount of bugs in what you code, make it easier to multithread and multitask, and bring your code closer to the business rules it is implementing than the mechanics of it's implementation. 这些技术将减少代码中的错误数量,使多线程和多任务更容易实现,并使您的代码比其实现机制更接近其正在实现的业务规则。

Now, there are other reasons to learn Scala in particular. 现在,还有其他原因特别需要学习Scala。 Those above, though, are my reasons you may want to learn functional programming. 但是,以上这些是我可能想要学习函数式编程的原因。

Learning a functional language definitely makes sense. 学习功能语言绝对是有道理的。 As Eric Raymond says, if you learn a functional language, it will make you a better programmer in the language of your choice. 正如埃里克·雷蒙德(Eric Raymond)所说,如果您学习一种功能语言, 它将使您成为使用所选语言的更好的程序员

From an industry perspective, if you can write good code in a functional language such as Haskell or Objective Caml, you will suddenly be in very high demand for a very small number of positions. 从行业角度来看,如果您可以用Haskell或Objective Caml之类的功能语言编写良好的代码,您将突然对很少数量的职位提出很高的要求。 It's not clear whether any sensible person would consider this a 'pro', but there are certainly a few very interesting companies that have openings that are for functional programmers only. 尚不清楚是否有理智的人会认为这是“专业人士”,但是肯定有一些非常有趣的公司提供仅适用于函数式程序员的职位。

Yes, it makes perfect sense, and is immediately useful in some common tasks you might encounter in production (even if you write them in Java). 是的,它非常有意义,并且在生产中可能会遇到的一些常见任务中立即有用(即使您使用Java编写它们)。 For example, if you will ever need to write a parser (for a DSL, for example), you'll find that using functional techniques to do so leads to much cleaner and more concise code. 例如,如果您将需要编写一个解析器(例如,对于DSL),则会发现使用功能性技术可以使代码更加简洁明了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM