ITPUB

不同程序员的老婆生了娃,他们的代码长啥样?笑死!

程序员在产房外等老婆生娃,闲着无聊用代码写个出生证明~
Image
1、面向对象の文艺青年(Python)
连娃的出生时间都要精确到毫秒,程序员爹怕不是个处女座:
Image
import datetime
class NewbornBaby:    def __init__(self):        self.birth_time = datetime.datetime.now()  # 精确到毫秒的仪式感        self.gender = "女"       # 贴心小棉袄        self.weight = 3.9       # 公斤        self.height = 50        # 单位厘米
    def welcome_to_the_world(self):        print("欢迎来到世界,宝贝!")        # 标准出厂欢迎语
baby = NewbornBaby()baby.welcome_to_the_world()  # 输出:欢迎来到世界,宝贝!
2、Java -- OOP 狂魔
生个娃都要写 getter,不愧是 Java 程序员,这代码量比娃的体重还重,JVM 看了都流泪:
Image
import java.time.LocalDateTime;
public class NewbornBaby {    private final LocalDateTime birthTime;    private final String gender;    private final double weight;    private final int height;
    publicNewbornBaby() {        this.birthTime = LocalDateTime.now();        this.gender = "女";        this.weight = 3.9;        this.height = 50;    }
    publicvoidwelcomeToTheWorld() {        System.out.println("欢迎来到世界,宝贝!");    }
    // 自动生成的getter方法(必须要有!)    public LocalDateTime getBirthTime() { return birthTime; }    public String getGender() { return gender; }    publicdoublegetWeight() { return weight; }    publicintgetHeight() { return height; }}
3、野生 JS 程序员の骚操作
娃连性别都是随机的~
Image
const baby = {    birthTime: new Date(),    gender: Math.random() > 0.5 ? "男" : "女",  // 随机抽卡    weight: 3.5 + Math.random(),               // 玄学体重    welcome: () => console.log("哇~")        // 迷惑行为};
baby.welcome();  // 输出:哇~
4、C++ 内存管理狂魔 
连娃都要放在栈上分配,怕内存泄漏是吧?
Image
#include<iostream>#include<ctime>
class NewbornBaby {public:    NewbornBaby() {        time(&birthTime);        gender = "女";        weight = 3.9;        height = 50;    }
    voidwelcomeToTheWorld(){        std::cout << "欢迎来到世界,宝贝!" << std::endl;    }
private:    time_t birthTime;    std::string gender;    double weight;    int height;};
5、Go 简洁但固执
连娃的结构体都要严格对齐,强迫症晚期:
Image
package main
import (    "fmt"    "time")
type NewbornBaby struct {    birthTime time.Time    gender    string    weight    float64    height    int}
func(b *NewbornBaby) welcomeToTheWorld() {    fmt.Println("欢迎来到世界,宝贝!")}
funcmain() {    baby := NewbornBaby{        time.Now(),        "女",        3.9,        50,    }    baby.welcomeToTheWorld()}

6、 PHP 祖传代码,上古卷轴

连娃都是数组生的,以后肯定是个JSON,welcome 还是匿名函数,亲爹都不给个正经方法?

Image
<?php$baby = [    'birth_time' => date('Y-m-d H:i:s'),    'gender' => '女',    'weight' => 3.9,    'height' => 50,    'welcome' => function() {        echo "哇~哇~哇~";    }];
$baby['welcome']();  // 输出:哇~哇~哇~?>

7、Bash 硬核派 

生个娃都要写 shell 脚本,娃以后肯定是个运维:

Image
#!/bin/bash
birth_time=$(date "+%Y-%m-%d %H:%M:%S")gender="女"weight=3.9height=50
function welcome_to_the_world() {    echo "欢迎来到世界,宝贝!"}
welcome_to_the_world
8、HTML 程序员版本
生个娃都要套 div,孩子以后肯定是个前端切图仔~
Image
<divclass="newborn"gender="女"weight="3.9kg"height="50cm">  <h1>欢迎来到世界!</h1>  <!-- 注释:CSS样式还没写 --></div>
9、CSS 程序员版本
建议加个@keyframes让娃动起来,不然太静态:
Image
#baby {    "birth_time": "3000-01-01 12:00:00",    "gender": "女",    "color": yellow,    "eye_color": "blue",    "hair_color": "brown",    "weight": 3.9,    "height": 50,    "welcome_message": "哇~哇~哇~"}

10、C# 混子版本

var 关键字暴露了你是个 C# 混子:

Image
var 我儿 = new {    生日 = DateTime.Now,     性别 = "男",             体重 = 4.2,             身高 = 52           };

- END -

IT168与ITPUB技术社区强强联手,收集数百款主流数据库产品,重磅推出“数据库全景图”,旨在打造一款集知识普及、产品对比、选型参考于一体的综合性资源平台。“数据库全景图(11月版)”可扫描上方左侧二维码回复关键词获取,识别右侧二维码直达“数据库全景图”链接(右上角浏览器打开获取更好体验)。

Image