不同程序员的老婆生了娃,他们的代码长啥样?笑死!
import datetimeclass 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() # 输出:欢迎来到世界,宝贝!
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; }}
const baby = {birthTime: new Date(),gender: Math.random() > 0.5 ? "男" : "女", // 随机抽卡weight: 3.5 + Math.random(), // 玄学体重welcome: () => console.log("哇~") // 迷惑行为};baby.welcome(); // 输出:哇~
#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;};
package mainimport ("fmt""time")type NewbornBaby struct {birthTime time.Timegender stringweight float64height int}func(b *NewbornBaby) welcomeToTheWorld() {fmt.Println("欢迎来到世界,宝贝!")}funcmain() {baby := NewbornBaby{time.Now(),"女",3.9,50,}baby.welcomeToTheWorld()}
6、 PHP 祖传代码,上古卷轴
连娃都是数组生的,以后肯定是个JSON,welcome 还是匿名函数,亲爹都不给个正经方法?
<?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 脚本,娃以后肯定是个运维:
#!/bin/bashbirth_time=$(date "+%Y-%m-%d %H:%M:%S")gender="女"weight=3.9height=50function welcome_to_the_world() {echo "欢迎来到世界,宝贝!"}welcome_to_the_world
<divclass="newborn"gender="女"weight="3.9kg"height="50cm"><h1>欢迎来到世界!</h1><!-- 注释:CSS样式还没写 --></div>
#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# 混子:
var 我儿 = new{生日 = DateTime.Now,性别 = "男",体重 = 4.2,身高 = 52};
- END -
IT168与ITPUB技术社区强强联手,收集数百款主流数据库产品,重磅推出“数据库全景图”,旨在打造一款集知识普及、产品对比、选型参考于一体的综合性资源平台。“数据库全景图(11月版)”可扫描上方左侧二维码回复关键词获取,识别右侧二维码直达“数据库全景图”链接(右上角浏览器打开获取更好体验)。