猫史档案馆


手把手教你写让路卡大喊f**k的代码

用户:SKQASKQA查看:9 回复:4 评论:9 创建时间:2022-08-07T16:15:42


在写代码时我已经喊过好几次f**k了,所以今天来保姆级教学,手把手教你写让路卡大喊f**k的代码!

1. 变量名越难理解越好,尽量不要统一命名法,可以混用命名法

//差的代码:
let text='Hello'
var inGame=false
const q=world.querySelectorAll

//好的代码:
let _a='Hello'
var notInGame=true
const world_querySelectorAll=world.querySelectorAll

2. 不要使用任何合理的换行、缩进

//差的代码:
world.onPlayerJoin(({entity})=>{
    if(black.includes(entity.player.name)){
        return entity.player.kick()
    }
})

//好的代码:
world.onPlayerJoin(
$=>black[
    'includes'
]($.player.name)&&entity.player.kick(
))

3. 能用内置函数一行解决的问题不要用,试着拆成几行,尽管你写完根本不会看第二眼

//差的代码:
global.find=n=>world.querySelectorAll('player').find(e=>e.player.name==n)

//好的代码:
global.find=function(name){
for(const e of world.querySelectorAll('player')){if(e.player.name==name){
return e}
}
return '没有这个玩家' //这段代码非常重要必不可少,这是你的"Plan B",尽管你根本不会用到
}

4. 能用数组对象解决的问题绝不用,试着使用if判断

//差的代码:
const levels={5:'萌新',50:'中手',500:'大佬',5000:'大神'}
const getLevel=entity=>{
    for(let e in levels){
        if(entity.level<e){
            return levels[e]
        }
    }
}

//好的代码:
const getLevel=function(entity){
    if(entity.level<5){
        return '萌新'
    }else if(entity.level<50){
        return '中手'
    }else if(entity.level<500){
        return '大佬'
    }else if(entity.level<5000){
        return '大神'
    }
}

5. 让你的代码充满废话

//差的代码:
global.randint=(min,max)=>Math.floor(Math.random()*(hi+1-lo)+lo)

//好的代码:
global.getRandomInteger=function(mininum,maxinum){
mininum=Math.floor(mininum)
    maxinum=Math.ceil(maxinum) //这两行也非常重要必不可少,尽管后面已经有Math.floor了
return Math.floor(Math.random()*(maxinum+1-mininum)+mininum)}

你学废了吗?快来试试吧!


回复

上一页1 页 / 共 1下一页
无极玄天无极玄天

sofa

话说我不理解为啥可以写出这么奇怪的代码

点赞0


评论


yee剑走天下yee剑走天下

。。。

内涵我好玩吗()()()emotion_doge

 

点赞0


评论


array_已退array_已退

center_image

改写了一份吉吉喵的代码,看一下能不能让你喊出F**K()

点赞1


评论


yee剑走天下yee剑走天下

那个随机数代码不是写成这样更简便吗()

globalThis.randint = (min, max) => Math.floor(Math.random() * max - min + min)

点赞0


评论