实力坑爹!个个让人崩溃的代码,你写过几个!

2019-06-20 18:46:15 浏览数 (1)

作为一个程序员,你看过哪些坑爹代码,你又写过多少坑爹代码,还有多少你不知道的坑爹代码?

给大家推荐码云上建的一个代码仓库:bullshit-codes,这个仓库了了收集很多坑爹代码,可以让别人不掉坑或者少掉坑,可以避免自己掉坑,或许哈哈一乐!

上边汇聚了各种编程语言的,仓库地址如下:

https://gitee.com/oschina/bullshit-codes

这些坑爹代码,可以让别人不掉坑或者少掉坑,可以避免自己掉坑,或许哈哈一乐。

实力坑爹 | 看看都有什么坑?

1. 你是否曾经这样使用过这样的return?

代码语言:javascript复制
/// <summary>/// 返回值加三元运算符值/// 好像没什么不对 -_-!/// </summary>/// <param name="inputValue"></param>/// <param name="type"></param>/// <returns></returns>public static int GetValue(int inputValue, int type){    return inputValue   type == 1 ? 1 : 2;}

2. 年假计算,这个程序员最后应该晋升为总监了,“xxx”应该是给ceo 准备的后门。

代码语言:javascript复制
import java.util.Scanner;
public class AnnualLeaveCalculation {
  public int calculation(User user) {    if ("xxx".equal(user.getUsername())) {         return 100;    } else {      int year = DateUtil.daysBetween(new Date(), user.getHireDate()) / 365;      if(year == 0) {        return 5;      } else if(year > 1 && year <= 5) {        return 7      } else if(year > 5 && year <= 10) {        return 9;      } else if(year > 10) {        return 10;      }    }  }    class User{    /** 用户名 */    private String username;    /** 入职日期 */    private Date hireDate;  }}

3. 有没有感觉这段代码特别特别啰嗦,不够简洁

代码语言:javascript复制
public boolean isFavorite(String articleKey, User user) {    boolean isFavorite = false;    if (user == null) {        return false;    }    long userId = user.getId();    Article article = getByArticleKey(articleKey);    if (null == article) {        return false;    }    List<Long> list = listAttentionUsers(article);    if (list == null || list.size() <= 0) {        return false;    }    for (Long id : list) {        if (id == userId) {            isFavorite = true;            break;        }    }    return isFavorite;}

4. N个if,资深程序员的最爱

代码语言:javascript复制
import java.util.Scanner;import org.junit.Test;
/*** *  * 一个工作好几年的代码 *  */
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释 
* public class CarInfo {  public CarInfoOutPut queryAllCatMonitor(Long orderId) throws ParseException {    /**获取运单基本信息**/    CarMonitorOutPut car = dao.getCar(orderId);    CarTankRecent carTankRecent;    CarInfoOutPut carInfoOutPut = new CarInfoOutPut();    if(null!=car){       carTankRecent = carService.getCarTankRecent(car.getTractorPlate());        /**车速**/        if(carTankRecent!=null){           car.setSpeed(carTankRecent.getMph());        }else{           car.setSpeed(0D);        }        List<TaskInformationOutPut> list=new ArrayList<TaskInformationOutPut>();    List<LoadTaskInformationOutPut> queryALLTask = dao.queryALLTask(orderId);    for (LoadTaskInformationOutPut loadTaskInformationOutPut : queryALLTask) {        if(loadTaskInformationOutPut.getType()==0){          TaskInformationOutPut one = new TaskInformationOutPut();          TaskInformationOutPut two = new TaskInformationOutPut();          TaskInformationOutPut three = new TaskInformationOutPut();          TaskInformationOutPut four = new TaskInformationOutPut();          loadTaskInformationOutPut.getArriveTime();          if(null!=loadTaskInformationOutPut.getArriveTime()){               one.setTaskInfo("已经到达");               one.setTaskType("装液");               one.setSignType("到达");               one.setTagName("装液信息");               one.setTime(loadTaskInformationOutPut.getArriveTime());               one.setCustomerName(loadTaskInformationOutPut.getCustomerName());               one.setLng(loadTaskInformationOutPut.getLng());               one.setLat(loadTaskInformationOutPut.getLat());               car.setState("已经到达,前往下一个任务点");               list.add(one);          }          if(loadTaskInformationOutPut.getLoadTime()!=null){            two.setTaskInfo("开始装液");            two.setTaskType("装液");            two.setSignType("装液");            two.setTagName("装液信息");            two.setTime(loadTaskInformationOutPut.getLoadTime());            two.setCustomerName(loadTaskInformationOutPut.getCustomerName());            two.setLng(loadTaskInformationOutPut.getLng());            two.setLat(loadTaskInformationOutPut.getLat());              car.setState("开始装液,前往下一个任务点");              list.add(two);          }          if(loadTaskInformationOutPut.getLeaveTime()!=null){            three.setTaskInfo("完成装液");            three.setTaskType("装液");            three.setSignType("离开");            three.setTagName("装液信息");            three.setTime(loadTaskInformationOutPut.getLeaveTime());            three.setCustomerName(loadTaskInformationOutPut.getCustomerName());            three.setLng(loadTaskInformationOutPut.getLng());            three.setLat(loadTaskInformationOutPut.getLat());              car.setState("完成装液,前往下一个任务点");              list.add(three);          }          if(loadTaskInformationOutPut.getReceiptTime()!=null&&loadTaskInformationOutPut.getPumpUrl()!=null){            four.setTaskInfo("装液回单");            four.setTaskType("装液");            four.setSignType("装液回单");            four.setTagName("回单信息");            four.setTime(loadTaskInformationOutPut.getReceiptTime());            four.setPumpUrl(loadTaskInformationOutPut.getPumpUrl());            four.setLoadWeigth(loadTaskInformationOutPut.getLoadWeigth());            four.setCustomerName(loadTaskInformationOutPut.getCustomerName());            four.setLng(loadTaskInformationOutPut.getLng());            four.setLat(loadTaskInformationOutPut.getLat());              car.setState("装液回单,前往下一个任务点");              list.add(four);          }                  }        if(loadTaskInformationOutPut.getType()==1){          TaskInformationOutPut one = new TaskInformationOutPut();          TaskInformationOutPut two = new TaskInformationOutPut();          TaskInformationOutPut three = new TaskInformationOutPut();          TaskInformationOutPut four = new TaskInformationOutPut();          if(loadTaskInformationOutPut.getArriveTime()!=null){          one.setTaskInfo("已经到达");          one.setTaskType("卸液");          one.setSignType("到达");          one.setTagName("卸液信息");          one.setTime(loadTaskInformationOutPut.getArriveTime());          one.setCustomerName(loadTaskInformationOutPut.getCustomerName());          one.setLng(loadTaskInformationOutPut.getLng());          one.setLat(loadTaskInformationOutPut.getLat());          car.setState("到达卸液地点,前往下一个任务点");          list.add(one);          }          if(loadTaskInformationOutPut.getLoadTime()!=null){              two.setTaskInfo("开始卸液");              two.setTaskType("卸液");              two.setSignType("卸液");              two.setTagName("卸液信息");            two.setTime(loadTaskInformationOutPut.getLoadTime());            two.setCustomerName(loadTaskInformationOutPut.getCustomerName());            two.setLng(loadTaskInformationOutPut.getLng());            two.setLat(loadTaskInformationOutPut.getLat());            list.add(two);            car.setState("开始卸液,前往下一个任务点");          }          if(loadTaskInformationOutPut.getLeaveTime()!=null){              three.setTaskInfo("完成卸液");              three.setTaskType("卸液");              three.setSignType("离开");              three.setTagName("卸液信息");              three.setTime(loadTaskInformationOutPut.getLeaveTime());              three.setCustomerName(loadTaskInformationOutPut.getCustomerName());              three.setLng(loadTaskInformationOutPut.getLng());              three.setLat(loadTaskInformationOutPut.getLat());              list.add(three);              car.setState("完成卸液,前往下一个任务点");          }          if(loadTaskInformationOutPut.getReceiptTime()!=null&&loadTaskInformationOutPut.getPumpUrl()!=null){            four.setTaskInfo("卸液回单");            four.setTaskType("卸液");            four.setSignType("卸液回单");            four.setTagName("回单信息");            four.setPumpUrl(loadTaskInformationOutPut.getPumpUrl());            four.setLoadWeigth(loadTaskInformationOutPut.getLoadWeigth());            four.setTime(loadTaskInformationOutPut.getReceiptTime());            four.setCustomerName(loadTaskInformationOutPut.getCustomerName());            four.setLng(loadTaskInformationOutPut.getLng());            four.setLat(loadTaskInformationOutPut.getLat());            list.add(four);            car.setState("完成卸液,前往下一个任务点");          }        }        if(loadTaskInformationOutPut.getType()==2){          TaskInformationOutPut one = new TaskInformationOutPut();          TaskInformationOutPut two = new TaskInformationOutPut();          TaskInformationOutPut three = new TaskInformationOutPut();          TaskInformationOutPut four = new TaskInformationOutPut();          if(loadTaskInformationOutPut.getLoadTime()!=null){          one.setTaskInfo("已经到达");          one.setTaskType("倒液");          one.setSignType("到达");          one.setTagName("倒液信息");          one.setTime(loadTaskInformationOutPut.getArriveTime());          one.setCustomerName(loadTaskInformationOutPut.getCustomerName());          one.setLng(loadTaskInformationOutPut.getLng());          one.setLat(loadTaskInformationOutPut.getLat());          list.add(one);          car.setState("到达倒液地点,前往下一个任务点");          }          if(loadTaskInformationOutPut.getLoadTime()!=null){              two.setTaskInfo("开始倒液");              two.setTaskType("倒液");              two.setSignType("倒液");              two.setTagName("倒液信息");            two.setTime(loadTaskInformationOutPut.getLoadTime());            two.setCustomerName(loadTaskInformationOutPut.getCustomerName());            two.setLng(loadTaskInformationOutPut.getLng());            two.setLat(loadTaskInformationOutPut.getLat());            list.add(two);            car.setState("开始倒液,前往下一个任务点");          }          if(loadTaskInformationOutPut.getLeaveTime()!=null){              three.setTaskInfo("完成倒液");              three.setTaskType("倒液");              three.setSignType("离开");              three.setTagName("倒液信息");              three.setTime(loadTaskInformationOutPut.getLeaveTime());              three.setCustomerName(loadTaskInformationOutPut.getCustomerName());              three.setLng(loadTaskInformationOutPut.getLng());              three.setLat(loadTaskInformationOutPut.getLat());              list.add(three);              car.setState("完成倒液,前往下一个任务点");                        }          if(loadTaskInformationOutPut.getReceiptTime()!=null&&loadTaskInformationOutPut.getPumpUrl()!=null){            four.setTaskInfo("倒液回单");            four.setTaskType("倒液");            four.setSignType("倒液回单");            four.setTagName("回单信息");            four.setPumpUrl(loadTaskInformationOutPut.getPumpUrl());            four.setLoadWeigth(loadTaskInformationOutPut.getLoadWeigth());            four.setTime(loadTaskInformationOutPut.getReceiptTime());            four.setCustomerName(loadTaskInformationOutPut.getCustomerName());            four.setLng(loadTaskInformationOutPut.getLng());            four.setLat(loadTaskInformationOutPut.getLat());            list.add(four);            car.setState("倒液回单,准备返程");          }      }    }    carInfoOutPut.setCar(car);    carInfoOutPut.setTask(list);  }    return carInfoOutPut;  }
*/

本文给大家整理了几个比较坑爹的代码,整理了几个之后,实在整理不下去了,仅供大家参考,看看能不能崩溃掉!!!

0 人点赞