LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Blogs > Bits and Pixels
User Name
Password

Notices

Concerning free software, programming, and whatever else I find interesting. Also the blog for my Web site, frigidcode.com.
Rate this Entry

C++ had lambda functions!

Posted 01-31-2013 at 02:21 AM by hydraMax

I'm doing a CS class which forces me to use C++. I was not very excited about this. However, I have recently be greatly encouraged by the discovery that C++ does, in fact, have lambda functions (or, more properly, anonymous functions) at least in the C++11 standard:

https://en.wikipedia.org/wiki/Anonym...ctions#C.2B.2B

Basically, the big deal here is that I can construct new functions /inside/ of other functions, and even capture variables from the context. This, in turn, means that I can pass in customized or constructed functions into other functions, and thus program in a more functional programming style.

So, for example, instead of creating a function that reads lines and parses them, I can create a function that reads lines, and receives (as a parameter) a function that parses strings. This means that (1) I can keep the two functionality concepts distinct in the code (reading lines and parsing strings) and (2) the code can be easily re-factored, because I can replace the parsing function with another function that parses different, or I can reuse the parsing function as an argument to another function that retrieves strings in a different way.

I suppose I could do something similar with classes; but then I would have to muck around with setting up a sensible inheritance tree, and that does not appeal to me in the slightest.
Posted in Uncategorized
Views 460 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration