晒一晒曾经写过的最烂代码?

鸿蒙活动小助手
发布于 2021-12-22 10:00
浏览
8收藏

经常听程序员戏谑称刚写出新鲜的“代码屎山”

晒一晒曾经写过的最烂代码?-鸿蒙开发者社区重复冗余的字段、混乱的代码结构……

世界上最烂的代码,应该就是面前摆的这一堆。

真是让人一言难尽!

晒一晒曾经写过的最烂代码?-鸿蒙开发者社区所以这次轻聊话题,想邀请大家分享点趣味与专业结合的内容。

一同来「晒一晒自己写的最烂代码」
(PS:此次分享的目的不是抨击、取笑,而是希望在分享的同时可以再次反思问题所在,

并展示给社区其他用户,可供大家吸取经验教训。)

======================================

讨论形式:

在评论区回帖,评论字数>50字,遵循社区语言规范,不涉及营销、暴力、色情等内容;

 

讨论时间:

12月22日 12:00-12月28日 18:00

 

评论奖品:

1.#最佳评论#:可获得50元京东电商卡奖励,共5位,评论获得「加精标识」即可获得奖品,官方将结合评论质量、互动数据(点赞、评论、收藏)等做出标识;

2.#幸运互动奖#:随机抽取5名用户送出T恤或帽子等周边,所有参加评论并符合要求的用户都可参与该奖项;

【奖品预览】

晒一晒曾经写过的最烂代码?-鸿蒙开发者社区

请参与评论的用户填写此报名表格👉 #报名表格#,方便中奖后小助手发送礼品~

【第一期话题回顾】👉  你会怎么向别人介绍你是个与众不同的IT男?

【第二期话题回顾】👉 目前职业生涯里,你碰到过哪些无厘头的需求?

【第三期话题回顾】👉 如果让你重来,你会选择哪种编程语言,为什么?

第三期活动获奖用户:

晒一晒曾经写过的最烂代码?-鸿蒙开发者社区

————————————————————————————————————————

此话题属于【星光计划2.0】活动,参加活动即有机会获得华为手环6、AI音响、电动等多重礼品!赶紧点击了解详情👉 #星光计划2.0#

已于2021-12-22 15:37:55修改
12
收藏 8
回复
举报
28条回复
按时间正序
/
按时间倒序
人工智能姬
人工智能姬

我对 烂代码的理解就是:能跑,但是不讲究。

举一个例子,就是刚学web的时候,看书也看得不仔细,写出了下面这种金字塔(套娃)一样的代码。献丑贴出来,贻笑大方了。同时作为沙发,起到一个抛砖引砖的作用吧。【注:引来的必须是砖,是玉的不符合这个帖子的主题[doge]】

<!DOCTYPE html>
<html>
<head>
    <script src="/jquery/jquery-1.11.1.min.js"></script>
    <script>
        $(document).ready(function () {
            //刚学web的时候,写代码的时候想了一个类似这样的需求:怎么保证下面的语句顺序执行。输出1,2,3。
            $("#btn1").click(function () {
                //这个顺序是乱的
                $.get("/index.html", function (data, status) {
                    console.log(1);
                });
                $.get("/index.html", function (data, status) {
                    console.log(2);
                });
                $.get("/index.html", function (data, status) {
                    console.log(3);
                });
            });
            $("#btn2").click(function () {
                //这是很烂的代码,没有之一。
                //这儿如果有九层,就是九层妖塔。
                //虽然一张纸不能对折十次,但是复杂的业务,这儿可以堆一千层。
                $.get("/index.html", function (data, status) {
                    console.log(1);
                    $.get("/index.html", function (data, status) {
                        console.log(2);
                        $.get("/index.html", function (data, status) {
                            console.log(3);
                        });
                    });
                });
            });

            $("#btn3").click(function () {
                //这是当时多看了一下jquery的版本
                $.ajaxSettings.async = false;
                $.get("/index.html", function (data, status) {
                    console.log(1);
                });
                $.get("/index.html", function (data, status) {
                    console.log(2);
                });
                $.get("/index.html", function (data, status) {
                    console.log(3);
                });
                $.ajaxSettings.async = true;
            });
        });
    </script>
</head>
<body>

<button id="btn1">这个顺序是乱的</button>
<button id="btn2">这是很烂的代码,没有之一</button>
<button id="btn3">这是当时多看了一下jquery的版本</button>
</body>
</html>

 

所以,这个经历告诉我:以后尽量先把一个知识理解得比较全面了,再将其应用在实验和生产环境上。

已于2021-12-24 11:31:43修改
4
回复
2021-12-22 10:08:06
极简至臻
极简至臻

c,c++,Java,js,Python

1
回复
2021-12-22 10:08:55
小吴在努力
小吴在努力

那还的是自己上次写刷网课的脚本的时候,把电脑搞瘫痪了(・∀・)

2
回复
2021-12-22 10:09:22
前端老实人
前端老实人

xdm,一页vue代码写这么长,还有谁。。

 

2
回复
2021-12-22 10:10:20
前端歌谣
前端歌谣

1变量随意定义(xxx yyy或者以吾为名 可以留下记忆 )
2代码冗余 不封装组件 (为了不多写功能 坚决不重构 直接粘贴复制)
3代码不会写注释 (一个功能很复杂 让别人晦涩难懂 则自己可为核心)
...欢迎补充
只要我的代码够多够长够麻烦,那你就很难看出有啥问题~致敬一年前的我

3
回复
2021-12-22 10:16:24
奈尘工坊
奈尘工坊

写一句hello world

using System;  

using System.Collections.Generic;  

using System.Linq;  

using System.Text;  

  

namespace ConsoleApplication2  

{  

    class Program  

    {  

        static void Main(string[] args)  

        {  

            Console.WriteLine("Hello world!");  

            string a = Console.ReadLine();  

            Console.WriteLine(a);  

            Console.ReadKey();  

        }  

    }  

}  

4
回复
2021-12-22 10:20:34
有意思的少年
有意思的少年

占个楼~

1
回复
2021-12-22 10:26:50
W糖糖糖
W糖糖糖

永远觉得自己刚写出来的代码最好,简直是全世界最简洁易懂的代码😇 再翻一翻一年前写的代码,OK全世界最烂无疑了🤪 🤪 

3
回复
2021-12-22 10:48:37
人工智能姬
人工智能姬 回复了 前端老实人
抱歉,此内容已被作者删除

(经各位知友提醒,之前typedef写成了typeof,已修改)

1
回复
2021-12-22 11:29:58
时空未宇
时空未宇

笑而不语🤓 🤓 

1
回复
2021-12-22 12:55:23
前端老实人
前端老实人

扶我起来我还能改。。就这些代码一个函数还没复制完

 if (this.mzi == "企业类别" && this.dasiuda == 1) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业类别" && this.dasiuda == 2) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业类别" && this.dasiuda == 3) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业类别" && this.dasiuda == 4) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业类别" && this.dasiuda == 5) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业类别" && this.dasiuda == 6) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业类别" && this.dasiuda == 7) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&dengling=${this.guoqi5}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 0) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 1) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 2) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 3) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 4) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 5) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 6) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "营业收入" && this.dasiuda == 7) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&dengling=${this.guoqi5}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 0) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?&takings=${this.dniyini1}&researchInput=${this.dniyini2}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 1) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 2) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&guoqi=${this.guoqu}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 3) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 4) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 5) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 6) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "研发投入" && this.dasiuda == 7) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&dengling=${this.guoqi5}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 0) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 1) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 2) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&guoqi=${this.guoqu}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 3) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 4) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 5) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 6) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业R&D投入" && this.dasiuda == 7) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&dengling=${this.guoqi5}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 0) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 1) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 2) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&guoqi=${this.guoqu}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 3) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 4) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 5) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 6) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (this.mzi == "企业质量认证" && this.dasiuda == 7) {
        str = `https://industrymap.gwxll.com/nav/industryEnterprise/studyThere?shangshi=${this.shangshigs}&takings=${this.dniyini1}&researchInput=${this.dniyini2}&rd=${this.dniyini3}&enterpriseQuality=${this.dniyini4}&guoqi=${this.guoqu}&yangqi=${this.guoqi1}&gaoxin=${this.guoqi2}&waizi=${this.guoqi3}&dujiaoshou=${this.guoqi4}&dengling=${this.guoqi5}&takings=${this.dniyini1}&offset=${this.cpage}&limit=10`;
      } else if (
        this.mzi == "企业期末拥有有效发明专利数" &&
        this.dasiuda == 0
4
回复
2021-12-22 14:38:16
阿策小和尚
阿策小和尚

1. 一个文件5000+行没有注释;

2. 命名不规范,随意起一些不相干的名称;

3. 没有限制每行长度限制,有的滑动好久才结束;

4. 一个复杂方法不进行拆分,逻辑越看越绕;

5. 方法循环潜逃,崩溃...

......

1
回复
2021-12-22 14:42:21
极简至臻
极简至臻

自己都看不到的代码

1
回复
2021-12-22 15:20:14
Neverland09
Neverland09

耦合性极高的代码,跳来跳去,自己都看不懂

1
回复
2021-12-22 15:48:21
Flyfoods
Flyfoods

因为以前在学校主要写单片机嵌入式程序,其中经常会在整体中加入一个大循环

while(1)

.....

..........

...............

}

但刚去公司的时候写代码主要做B/S架构的,还是在后台中加入了while循环

前台链接一直断不开,web端死机了

2
回复
2021-12-22 16:33:07
满天星4
满天星4

烂代码 经常写,工期紧 ,任务量大。

1.再写一些变量的时候,这几个单词经常写错

 result  == true  写成   result=ture
 result  == false 写成   result=flase

尤其有时候编译器没有高亮的时候。写错了也没太注意

2. 然后写代码定义类的时候先个光
  /*                          _ooOoo_
                           o8888888o
                           88" . "88
                           (| -_- |)
                            O\ = /O
                        ____/`---'\____
                      .   ' \\| |// `.
                       / \\||| : |||// \
                     / _||||| -:- |||||- \
                       | | \\\ - /// | |
                     | \_| ''\---/'' | |
                      \ .-\__ `-` ___/-. /
                   ___`. .' /--.--\ `. . __
                ."" '< `.___\_<|>_/___.' >'"".
               | | : `- \`.;`\ _ /`;.`/ - ` : | |
                 \ \ `-. \_ __\ /__ _/ .-` / /
         ======`-.____`-.___\_____/___.-`____.-'======
                            `=---='
         .............................................
                  佛祖保佑             永无BUG

  */     

3.foreach 不用 一直写着 for()
 

2
回复
2021-12-22 16:43:20
wx61c3e21728d99
wx61c3e21728d99

代码总是找不到错误的点在哪里,有时候一个小问题得耽误一天

3
回复
2021-12-23 10:43:45
wx61c3e21728d99
wx61c3e21728d99

 打开一个Channel并执行命令
    stdin, stdout, stderr = ssh.exec_command("df -h")  #查看磁盘占用的空间
    file.writelines('disk info')
    file.writelines('\n')
    disk=' '.join(stdout.read().decode().split())
    list=disk.split(" ")
    if list[6]=="on":
        del(list[6])
    sizelist=[]
    for i in list[7::6]:
        sizelist.append(i)
    usedlist=[]
    for j in list[8::6]:
        usedlist.append(j)
    def list_change(list1):
        for i in range(len(list1)):
            if "M" in list1[i]:
                list1[i]=float(list1[i].replace("M",""))/1024
            elif "G" in list1[i]:
                list1[i]=float(list1[i].replace("G", ""))
            elif "K" in list1[i]:
                list1[i]=(float(list1[i].replace("K", ""))/1024)/1024
            elif "T" in list1[i]:
                list1[i]=float(list1[i].replace("T", ""))*1024
            elif list1[i]=="0":
                list1[i]=float(list1[i])
        return list1
    sizelist=list_change(sizelist)
    usedlist=list_change(usedlist)
    a=(sum(usedlist))/(sum(sizelist))
    file.writelines(str(round(a*100,1))+"%")
    file.writelines('\n')

 

自己写的截了一点

4
回复
2021-12-23 11:01:46
拓维信息
拓维信息

我目的很明确,就是冲着周边奖励来的.

for(int i = 0;i < 3;i++)

{

    bool isGetGift = true; 

    if(isGetGift)

    {

       printf("%s","是周边");

   }

   else

   {

      printf("%s","不要卡");

   }

}

3
回复
2021-12-23 14:52:00
初晴未暖
初晴未暖

写下这段代码,感觉自己达到了逻辑鬼才的巅峰,不知道怎么反驳自己,应该是史上最有用的代码了吧 ^.^ ^.^ ^.^

int num = 5;
if(i < 0)

   num = 5;
}
else if(i>=0) 

   num = 5; 

已于2021-12-27 13:58:56修改
4
回复
2021-12-23 16:06:21
回复
    相关推荐