I dunno why people think functional programming jobs are vanishingly scarce. They are not. If you can demonstrate skill in functional languages, you might even get recruited.
It's true there are more wage-slave code-a-day jobs, but those jobs can be easily filled by uninspired hacks who are in it for the money. If you're reading this, the odds of you being one of those hacks is very low. The job market is smaller, but the workforce of talented functional programmers is much smaller, so the demand is still high.
And Clojure & Scala are even easier because you can get a java job and them worm them in. It's not difficult to make a compelling argument that Clojure & Scala are better at Java than Java is.
Functional programming jobs are scarce, but that's because no-one is a "functional programmer" in the same way that you might be a "PHP programmer". Instead you get lots of jobs where you happen to write a lot of code in a functional programming language but you don't look like a programmer in an organizational sense - you're an "analyst" or an "engineer" or whatever. That's where F# is making inroads.
You're not going to do functional (or any other interesting) programming as an IT programmer in a generic financial services company.
If you work for an actual software company (or perhaps an innovative financial services company) as a software engineer (or even on an operations team in some cases e.g., Sysadmins at Google using Haskell, ops tools at Yahoo once built in OCaml), there's plenty of chances to do functional programming (or something else that interests you).
It's just generally people are programmed to think "it's just a job" and choose their jobs based on salary, name recognition, commute hours etc... (Some also have very specialized skills like systems programming or machine learning and aren't particularly interested in programming languages, although I think they're missing out)
I really don't understand your point. What is the difference between a "programmer" and an "engineer"? Why doesn't "functional programmer" as a category include things like "F#", which you suggest is a valid category.
As for me, I interviewed at several jobs that featured functional programming during my last jobsearch. I actually turned down offers that were not devoted to functional (or at least hybrid object/functional) technologies.
If you are an analyst working for a bank, then your job is to do financial analysis to inform trading decisions. That is what your title is, that is the result you are expected to produce, that is what you will see yourself as. But to actually do that, you might be writing F# 40 hrs a week. You wouldn't consider yourself a programmer tho'. The program is not a product in and of itself; it's just a tool you use that you happen to also make yourself 'cos it's easier than writing a spec document and waiting for "a programmer" to do it.
Similarly if you are an engineer working for Ericcson on switches for telcos then you job is to design and implement switches. The result you are expected to produce is a switch that is better than the current one. You will probably see yourself as an electronic engineer - but you might actually be writing Erlang 40 hrs a week. The code isn't a product either - it's just the means by which you tell your switch hardware how to behave.
Whereas if you are a "PHP programmer" someone has already decided that PHP is what we're doing and your role is to do PHP and your end product is a website built with PHP. Which is not a bad thing mind - but it is why you see "PHP jobs" and you don't see so many "F# jobs".
The article actually contains the "if u cn rd ths..." phrase and it's a nice touch. However, it would be better to keep the original title and mention the phrase in the comments.
even worse for me, I clicked to find out why employers like citi and BofA in the financial sector were no longer able to afford vowels for their programmers.
def fact(n):
if (n <= 1):
return 1
else:
return n * fact(n-1)
1 line vs 5 lines doesn't seem like an advantage to me when it takes pretty much the same amount of time to read and understand the complicated 1 liner.
The main advantage of a 1-liner is that you can compose the whole thing and execute it without having to format anything. That is a nice feature for code that is only ever intended to be used once, such as from the python repl or some other shell. --Or more than once, for the duration of a session. It's a lot easier to use command history to get and modify a 1-liner than to replay a 5-line function definition.
When the code is primarily expressions, it's relatively easy to to this. Trying to do one-liners with regular python syntax can get tricky.
Also, if you have a series of similar relationships to present, it's often easier to line them up next to each other. You might cut 12 lines to 6 lines and the whole thing will be far clearer. Although in those cases, it's probably more effective to use a dictionary to achieve the same thing, with the advantage of data/logic separation.
The point was to demonstrate that the one-liner fits easily as an argument to 'python -c' from the command-line. You could also point out "import _if;" probably won't let me call "_if()", but again that wasn't really the point.
Also, you'll need to know the version of python:
$ python
Python 2.4.3 (#1, Dec 11 2006, 11:39:03)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> fact = lambda n: 1 if n <= 1 else n*fact(n-1)
File "<stdin>", line 1
fact = lambda n: 1 if n <= 1 else n*fact(n-1)
^
SyntaxError: invalid syntax
>>>
I understand you just copied the same snippet for your example. I'm just pointing out that Python does support that kind of if natively, so that people won't think that it doesn't.
Some of the responses are outdated, here's one of the things that is now part of python:
Python 2.5 introduced defaultdict in the collections module:
from collections import defaultdict
d = defaultdict(int)
d['foo'] +=1 # look ma! no error!
For this application, if you're using Python 2.7 there's now a Counter in collections, you can do the same as above, just call Counter(). You can also do:
c = Counter(iter) # iter is an iterable. It will count the elements!
Incidentally, most C-style-syntax languages have a ternary conditional operator, and I use it quite a lot for things like building strings, very small conditionals, etc.... When used correctly, it can improve readability and expressiveness quite a bit.
x = <test> ? <result> : <alternative>
Some times for slightly more complex expressions, I'll put them on separate lines so as to have a very compact if/else structure.
As pointed out in the OP, there are actually quite a lot of ways to simulate the ternary operator in Python. An interesting one is (result, alternative)[test]. If result and alternative are functions you could write it as (result, alternative)[test]().
It's true there are more wage-slave code-a-day jobs, but those jobs can be easily filled by uninspired hacks who are in it for the money. If you're reading this, the odds of you being one of those hacks is very low. The job market is smaller, but the workforce of talented functional programmers is much smaller, so the demand is still high.
And Clojure & Scala are even easier because you can get a java job and them worm them in. It's not difficult to make a compelling argument that Clojure & Scala are better at Java than Java is.