The objective of an assessment can vary from one lecture to another. Quite often, the point is simply to validate whether the expected learning outcomes of the lecture have been met. For instance, if an expected outcome is to know almost by heart how to write an array sorting program, then it's quite reasonable to ask to write a small amount of lines of code in a fixed amount of time.
If, on the other hand, the expected outcome is at a higher level of understanding (in the sense of Bloom's taxonomy), for instance by asking to design and assess a new data structure to handle a new problem, then it could be more reasonable to expect more time.
The problem you are referring to by "would never have such extreme time constraints in real life" is addressed with the notion of authentic learning (Rule, 2006), which identifies the four following themes for a learning to be authentic:
1) the activity involves real-world problems that mimic the work of professionals in the discipline with presentation of findings to audiences beyond the classroom;
2) open-ended inquiry, thinking skills, and metacognition are addressed;
3) students engage in discourse and social learning in a community of learners; and
4) students are empowered through choice to direct their own learning in relevant project work.
Authentic learning comes with its upsides and downsides (the reference linked acts as a survey paper, if you are interested), so it's not necessarily the best approach. In particular, (Lombardi, 2007) note that the reliance on traditional instruction is not simply a choice made by individual faculty—students often prefer it. For instance, not everybody wants to be tested on writing code in a highly complex environment, using bugged code written by other people, implementing specifications that are sub-optimal, but the client want them in this way, which could be a typical real world situation.
I don't think you should complain about time constraints, but if you believe that authentic learning would be more beneficial to you and your fellow students, you should probably discuss with the professor about the objective of the assessment.
Lombardi, M. M. (2007). Authentic learning for the 21st century: An overview. Educause learning initiative, 1(2007), 1-12.
Rule, Audrey C. (2006). The Components of Authentic Learning. Journal of Authentic Learning, Volume 3, Number 1, Pages 1-10, August 2006