转: Comparing Programming Languages in real life

本文将各种编程语言比喻为不同类型的女性角色,通过幽默的方式描述了每种语言的特点及适用场景。

转: Comparing Programming Languages in real life


There are so many programming languages available that it can be very difficult to get to know them all well enough to pick the right one for you. On the other hand most men know what kind of woman appeals to them. So here is a handy guide for many of the popular programming languages that describes what kind of women they would be if programming languages were women.

  • Assembler - A female track star who holds all the world speed records. She is hard and bumpy, and so is not that pleasant to embrace. She can cook up any meal, but needs a complete and detailed recipe. She is not beautiful or educated, and speaks in monosyllables like "MOV, JUMP, INC". She has a fierce and violent temper that make her the choice of last resort.
  • FORTRAN - Your grey-haired grandmother. People make fun of her just because she is old, but if you take the time to listen, you can learn from her experiences and her mistakes. During her lifetime she has acquired many useful skills in sewing and cooking (subroutine libraries) that no younger women can match, so be thankful she is still around. She has a notoriously bad temper and when angered will start yelling and throwing dishes. It was mostly her bad temper that made grand dad search for another wife.
  • COBOL - A plump secretary. She talks far too much, and most of what she says can be ignored. She works hard and long hours, but can't handle really complicated jobs. She has a short and unpredictable temper, so no one really likes working with her. She can cook meals for a huge family, but only knows bland recipes.
  • BASIC - The horny divorcee that lives next door. Her specialty is seducing young boys and it seems she is always readily available for them. She teaches them many amazing things, or at least they seem amazing because it is their) first experience. She is not that young herself, but because she was their first lover the boys always remember her fondly. Her cooking and sewing skills are mediocre, but largely irrelevant, it's the frolicking that the boys like. The opinion that adults have of Mrs. BASIC is varied. Shockingly, some fathers actually introduce their own sons to this immoral woman! But generally the more righteous adults try to correct the badly influenced young men by introducing them to well behaved women like Miss Pascal.
  • PL/I - A bordello madam. She wears silk dresses, diamonds, furs and red high heels. At one time she seemed very attractive, but now she just seems overweight and tacky. Tastes change.
  • C - A lady executive. An avid jogger, very healthy, and not too talkative. Is an good cook if you like spicy food. Unless you double check everything you say (through LINT) you can unleash her fierce temper. Her daughter C++ is still quite young and prone to tantrums, but it seems that she will grow up into a fine young woman of milder temper and more sophisticated character.
  • ALGOL 60 - Your father's wartime sweetheart, petite, well proportioned, and sweet tempered. She disappeared mysteriously during the war, but your dad still talks about her shapely form and their steamy romance. He never actually tasted much of her cooking.
  • Pascal - A grammar school teacher, and Algol 60's younger sister. Like her sister she is petite and attractive, but very bossy. She is a good cook but only if the recipe requires no more than one pot (module).
  • Modula II - A high-school teacher and Pascal's daughter. Very much like her mother, but she has learned to cook with more than one pot.
  • ALGOL 68 - Algol 60's niece. A high-society woman, well educated and terse. Few men can fully understand her when she talks, and her former lovers still discuss her mysterious personality. She is very choosy about her romances and won't take just any man as her lover. She hasn't been seen lately, and rumor has it that she died in a fall from an ivory tower.
  • LISP - She is an aging beatnik, who lives in a rural commune with her hippie cousins SMALLTALK and FORTH. Many men (mostly college students) who have visited the farmhouse,-- enthusiastically praise the natural food, and perpetual love-ins that take place there. Others criticize the long cooking times, and the abnormal sexual postures (prefix and postfix). Although these women seldom have full-time jobs, when they do work, their employers praise them for their imagination, but usually not for their efficiency.
  • APL - A fancy caterer specializing in Greek food. She can cook delicious meals for rows and rows of tables with dozens of people at each table. She doesn't talk much, as that would just slow her work down. Few people can understand her recipes, since they are in a foreign language, and are all recorded in mirror writing.
  • LOGO - A grade-school art teacher. She is just the kind of teacher that you wish you had when you were young. She is shapely and patient, but not an interesting conversationalist. She can cook up delicious kiddie snacks, but not full-course meals.
  • LUCID & PROLOG - These clever teenagers show a new kind of cooking skill. They can cook-up fine meals without the use of recipes, working solely from a description of the desired meal (declarative cooking). Many men are fascinated by this and have already proposed marriage. Others complain that the girls work very slowly, and that often the description of the meal must be just as long as a recipe would be. It is hard to predict what these girls will be like when they are fully mature.
  • Ada - A WAC colonel built like an amazon. She is always setting strict rules, but if you follow them, she keeps her temper. She is quite talkative, always spouting army regulations, and using obscure military talk. You gotta love her though, because the army says so.

  • Java - Bulky with big boobs. Does everything you want but slowly. Hardly complains about how you want it in bed. The kind of woman who is not sexy, but gives you amazing satisfaction. You have tried several women, but this one doesn't get off your mind so you always go back to her.

  • PHP - Slick and slim lady. Very portable. Does nice and amazing things with her small body. Very good in aerobics. Not very sexy but intact. She is the kind of women that most men are happy to wed, though she will need a house maid because she is unable to carry heavy workload.

  • Ruby on Rails. The new girl in town. Everybody is talking about her. Very beautiful and sexy. Only daring men, because she is till new, have the guts to ask her out. She is modern and sophisticated. Already a lot of myth is surrounding her with regards to her ability. She is not talkative but looks rather very intelligent.

  • C# - The pimp from next door! She likes copying everything, from recipes to makeup to fashion. She is never original and likes to still other women's ideas, then go about shouting that the ideas are hers. Those who are not aware of her source of ideas think she is very intelligent. She is very talkative and showy. Sometimes she is very good at perfecting what she has copied.

  • Python - The all complete lady who is the envy of the town. She came up with a slick new way of dressing that made her a hit. Those who initially scoffed at her new dressing later fell head over heals for it. She is not talkative, but when she does a job, she does it very well.

  • Visual Basic (Popularly known as VB) - The little bitch from next door. Probably the most dumb girl in town. She never turns a man down and all the boys in the neighbourhood use her as a training ground as they learn the ropes to adulthood. She never practise safe sex and regularly infects the whole system with memory leaks. Popularly known as VB, she is so loose a lot of fathers have spanked their sons for dating her. However, it is amazing how popular she is. Most men curse themselves once they taste lips of mature and sweet women. A lot of men have struggled to maintain decent relationships with mature women after being spoiled by this little brat! She doesn't have a clue how to cook a complete decent meal without throwing up into the pot!
### 使用 `Comparator.comparing` 实现类型换 在 Java 中,`Comparator.comparing()` 提供了一种简洁的方式来基于特定属性或函数创建比较器。该方法接受一个函数作为参数,此函数定义了要提取并用于比较的关键字段[^1]。 #### 基本语法 以下是 `Comparator.comparing` 的基本形式: ```java public static <T, U extends Comparable<? super U>> Comparator<T> comparing(Function<? super T, ? extends U> keyExtractor) ``` 其中,`keyExtractor` 是一个函数接口,通常通过 lambda 表达式或方法引用提供,用于从对象中提取可比较的键值。 当需要进行类型换时,可以通过自定义 `Function` 来完成这一过程。下面是一个具体的例子: --- #### 示例代码:字符串长度排序 假设有一个类 `Person`,我们希望按照名字的长度对其进行排序。 ```java import java.util.*; import java.util.function.Function; import java.util.Comparator; class Person { private String name; public Person(String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { return "Person{name='" + name + "'}"; } } public class Main { public static void main(String[] args) { List<Person> people = Arrays.asList( new Person("Alice"), new Person("Bob"), new Person("Christopher") ); // 按照名字长度升序排列 people.sort(Comparator.comparing(person -> person.getName().length())); System.out.println(people); } } ``` 上述代码展示了如何使用 `Comparator.comparing` 将 `String` 换为其长度(即整数)来实现排序。 --- #### 处理复杂场景:多级排序与类型换 如果需要进一步扩展功能,可以结合 `.thenComparing` 方法处理多个级别的排序逻辑。例如,在按年龄排序的基础上再按姓名降序排列: ```java List<Person> people = Arrays.asList( new Person("John", 25), new Person("Jane", 30), new Person("Doe", 25) ); // 首先按年龄升序,其次按名称降序 people.sort(Comparator.comparing(Person::getAge).thenComparing( Comparator.comparing((Person p) -> p.getName().toLowerCase(), Comparator.reverseOrder()) )); System.out.println(people); ``` 这里,`.thenComparing` 接收另一个比较器实例,允许我们在第一次比较相等的情况下应用额外的规则[^3]。 --- #### 双精度浮点数类型的排序 对于双精度浮点数值的排序,可以直接利用专门的方法 `comparingDouble` 或者手动传递映射函数给 `comparing`。例如: ```java class Student { private double percentageMarks; public Student(double percentageMarks) { this.percentageMarks = percentageMarks; } public double getPercentageMarks() { return percentageMarks; } @Override public String toString() { return "Student{percentageMarks=" + percentageMarks + "}"; } } public class Main { public static void main(String[] args) { List<Student> students = Arrays.asList( new Student(78.9), new Student(85.6), new Student(78.9) ); // 方式一:使用 comparingDouble students.sort(Comparator.comparingDouble(Student::getPercentageMarks)); // 方式二:使用 comparing 并显式指定 Double 类型 students.sort(Comparator.comparing(student -> student.getPercentageMarks())); System.out.println(students); } } ``` 两种方式均能正常工作,但推荐优先考虑专用方法如 `comparingInt`, `comparingLong`, 和 `comparingDouble`,因为它们性能更优且语义清晰[^4]。 --- ### 总结 `Comparator.comparing` 不仅简化了基于单个属性的排序操作,还支持复杂的类型换以及链式的多重条件排序。开发者只需关注核心业务逻辑——即如何抽取待比较的数据即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值