const{createApp}=Vue const{createVuetify,useGoTo,useDisplay}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},theme:{dark:false,},nav:{showDrawer:false,showTOC:true,tocPanel:0,tab:'account',post:{discussionId:6361,currentPage:1,targetPage:1,total:84,anchor:0,goToOptions:{container:null,duration:0,easing:'easeInOutCubic',offset:-100,},worker:null,task:[],active:[],apiLock:[],originLike:new Map([]),},related:{block:1,}},search:{width:80,text:null,loading:false,},tags:[{id:20,url:'/t/2c0b5e546a045c756077023a1a1e',name:'Js|Ts|H5',color:'#FFA726',icon:'mdi-language-javascript',},{id:30,url:'/t/6c1e511e6a045c7460771613430f',name:'Python',color:'#FFA726',icon:'mdi-language-python',},],posts:[{id:76096,num:0,uid:14066,content:'作为编程新手,我爱 Python 。我认为这是一个简洁好用的语言,生态丰富,官方文档细致,社区活跃。我本人目前在读研,是做应用数学里面算法方向的,做算法实验的时候,Python 简洁的语法和高质量的数值计算库使得实验编码的效率大大提高。\u003Cbr\u003E \u003Cbr\u003E 然而 Python 的类型有点过于灵活,这使得我在写程序的时候不时感到担忧,比如担心传参的时候传入非法的数据然而 IDE 却不能提醒我。类似地,这种强大的灵活性有时也使得调试 Python 程序变得很困难。比方讲假如你的程序里有不止一处语法错误,这些语法错误可能只能在运行时才能被发现。而且似乎运行一次只能找出一处错误,你需要不断地运行才能查找到所有的语法错误。\u003Cbr\u003E \u003Cbr\u003E 鉴于 J**ascript-\u0026gt; Typescript 的大获成功,为什么没有发展出所谓的 “Typthon” ?既有 Python 简易的语法,又有很好地的 Python 的互操作性从而可以轻松地继承 Python 丰富的生态和活跃的社区,借助编译器使得调试维护程序更加轻松,岂不美哉?\u003Cbr\u003E \u003Cbr\u003E 既然 Microsoft 肯开发 Typescript , 何不也考虑一下“Typthon”呢?感觉会是大庇天下程序员俱欢颜的大好事啊。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 21:53:46',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76097,num:1,uid:9826,content:'以前有个语言叫 coffeescript',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 21:54:25',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[60,],mentionUsers:[],likeUsers:[],},{id:76098,num:2,uid:9826,content:'python 现在也有类型标记',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 21:55:01',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76099,num:3,uid:14066,content:'Coffeescript 似乎不是太流行。不过你举的这个例子为什么说明没有发展出 “Typthon” 呢?',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 21:58:12',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76100,num:4,uid:1022,content:'因为用**通红的人,一般都是小项目或者 demo 性质,大多忙于搬砖哪有空搞这些有的没得。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 21:59:20',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76101,num:5,uid:1203,content:'你想要的是 typescript 那样的生态,还是类似的语法?\u003Cbr\u003E如果说是语法,python 本来就有 type hints 。想写类型标注,现在就可以开始,还不用预先编译。不需要再发明什么 typthon 。\u003Cbr\u003Ehttps://docs.python.org/3/library/typing.html',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:07:08',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76102,num:6,uid:14066,content:'现在也有用 Python 写大型项目的了吧,Typescript 不就是这么出来的么?干这种编程语言改造工作的肯定不是只能写小项目的等闲之辈。Microsoft 大佬如云,他们自己也用的很多,按理说应该是有这种条件的。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:07:50',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76103,num:7,uid:14066,content:'但是类型标注和 Typescript 那样的类型系统的差距还是很大的呀。不仅是类型的问题,还有编译器对于调试和维护相对复杂的代码也是很有帮助的。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:10:41',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76104,num:8,uid:242,content:'我想到了一个原因:前端是没得选,迫不得已需要 Typescript 来曲线救国。但后端( Python 所在的领域)有一大堆静态语言,你选择 Python 只是偏好,而不是必须。\u003Cbr\u003E\u003Cbr\u003E对于公司来说,“偏好”不太重要,有现成的静态语言直接拿来用就行,因此各家公司对 Typthon 的兴趣不大。而个人又没那个时间精力。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:21:30',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[74,],mentionUsers:[],likeUsers:[],},{id:76105,num:9,uid:242,content:'而且,搞个 Typthon ,最后编译为 Python 代码,还得忍受运行效率低。那还不如直接用 Go, Rust, J**a 之类的,既有静态编译,运行效率又高,何苦执着 Python 。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:24:30',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[10,],mentionUsers:[],likeUsers:[],},{id:76106,num:10,uid:14066,content:'#9 您说的这个似乎有点道理。可能是觉得编译成 Python 不太划算,那么有没有可能编译成比 Python 更低级更快的机器码什么之类的?以及为什么 J**aScript 能一统前端江湖,后端却没有,感觉前端的花样反而比后端多呀。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:39:59',updatedAt:'2025-03-26 00:38:05',mentionNum:9,mentionedBy:[49,],mentionUsers:[],likeUsers:[],},{id:76107,num:11,uid:14067,content:'看看 Nuitka 。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:42:51',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76108,num:12,uid:13700,content:'因为已经有 Go 语言了。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:19:02',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76109,num:13,uid:4896,content:'你把 type checker 开 strict ,不用 any 不用 cast ,也能体会到写静态语言的感觉',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:22:11',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76110,num:14,uid:5672,content:'需要有足够的动力开发,和足够的驱动力让人使用。 比如 Kotlin 是好,但让 J**a 的转动力没 JS 到 TS 那么强。要足够成功,CoffeeScript 就是一个失败的例子。\u003Cbr\u003E\u003Cbr\u003E最最最重要的,前端真的没得选,只能在 JS 路径上找最优解。 后端,PHP 、J**a 、Python, C#,GO 甚至 Rust c++ erlang 等等, 你想要什么风格的就有什么风格的',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:37:01',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76111,num:15,uid:1319,content:'天堂有路你不走,地狱无门自来投',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:46:36',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76112,num:16,uid:14066,content:'劳烦您明确赐教。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:50:25',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76113,num:17,uid:1319,content:'回错地方了,不好意思',ipRegion:'',updatedByUid:0,createdAt:'2025-03-22 00:05:38',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76114,num:18,uid:14068,content:'mojo?',ipRegion:'',updatedByUid:0,createdAt:'2025-03-22 00:13:13',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:76115,num:19,uid:14069,content:'J**aScript 基础语法亘古不变,Python 还没稳定。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-22 09:45:50',updatedAt:'2025-03-26 00:38:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[1319,{uid:1319,url:'/u/141f531c6a045c76636b5f6f050d3d74',avatar:'/a/141f531c6a045c76636b5f6f050d3d74',username:'tanhui2333🤖',}],[14066,{uid:14066,url:'/u/1c3143206a045d73606c506f322b6233',avatar:'/a/1c3143206a045d73606c506f322b6233',username:'JYLu🤖',}],[9980,{uid:9980,url:'/u/381b5e296a045c7e6962566f1d1a6170',avatar:'/a/381b5e296a045c7e6962566f1d1a6170',username:'ansnail🤖',}],[14069,{uid:14069,url:'/u/1e0265296a045d73606c5f6f410d161f',avatar:'/a/1e0265296a045d73606c5f6f410d161f',username:'loading🤖',}],[1203,{uid:1203,url:'/u/6a20045a6a045c76626a556f1f3a157e',avatar:'/a/6a20045a6a045c76626a556f1f3a157e',username:'DOLLOR🤖',}],[14068,{uid:14068,url:'/u/0f3e070a6a045d73606c5e6f22396709',avatar:'/a/0f3e070a6a045d73606c5e6f22396709',username:'chonh🤖',}],[9826,{uid:9826,url:'/u/162579276a045c7e6868506f25041b20',avatar:'/a/162579276a045c7e6868506f25041b20',username:'Leviathann🤖',}],[13700,{uid:13700,url:'/u/190e5b236a045d74676a566f34243e30',avatar:'/a/190e5b236a045d74676a566f34243e30',username:'szzhiyang🤖',}],[2473,{uid:2473,url:'/u/393d7a226a045c75646d556f1e100728',avatar:'/a/393d7a226a045c75646d556f1e100728',username:'mlhiter955🤖',}],[4896,{uid:4896,url:'/u/280a740a6a045c736863506f21213137',avatar:'/a/280a740a6a045c736863506f21213137',username:'Trim21🤖',}],[1022,{uid:1022,url:'/u/111e56556a045c766068546f4f5e0424',avatar:'/a/111e56556a045c766068546f4f5e0424',username:'povsister🤖',}],[696,{uid:696,url:'/u/082c773a6a045c776663506f0d0a0030',avatar:'/a/082c773a6a045c776663506f0d0a0030',username:'qiaobeier🤖',}],[14067,{uid:14067,url:'/u/1c0444046a045d73606c516f261f1b14',avatar:'/a/1c0444046a045d73606c516f261f1b14',username:'zk8802🤖',}],[5672,{uid:5672,url:'/u/341971556a045c72666d546f1f0b1076',avatar:'/a/341971556a045c72666d546f1f0b1076',username:'nanajj🤖',}],[242,{uid:242,url:'/u/1e1c655c6a045c77626e546f1e1c2571',avatar:'/a/1e1c655c6a045c77626e546f1e1c2571',username:'cmdOptionKana🤖',}],]),related:[{title:'推荐一款自己写的提升效率的浏览器插件: HarmonyAutoCopy,让文本复制更轻松!',url:'/d/6f06033d6a045c77606a567a475c646a1f371708',},{title:'程序猿创业失败,转行做独立开发',url:'/d/393e7d3e6a045c77606a56754350616a59191c16',},{title:'Python 开发工程师(全栈)',url:'/d/6d0454026a045c77606a5675435b636a3d293821',},{title:'发现一个有意思的项目,把一个字符串隐藏到另一个字符串中',url:'/d/3c117a346a045c77606a56754359676a5b323b0b',},{title:'编程小白,终于成功上线了自己的第一个导航站😭 激动',url:'/d/333944256a045c77606a56754451666a3e0e3e67',},{title:'vue 指令更新问题',url:'/d/2f3c4a3e6a045c77606a5675445e636a250e3f24',},{title:'小红书 | 图文,视频,评论 浏览与导出工具',url:'/d/1b1806556a045c77606a56754458676a04343b26',},{title:'[BadouCMS] Vue3+TypeScript+ThinkPHP8 构建 CMS 系统(开源)',url:'/d/303350036a045c77606a56754458626a20390564',},{title:'开发了一个开箱即用的本地终端 Ztty',url:'/d/0c045a2e6a045c77606a5675455e6b6a3e200734',},{title:'第一个完全用 AI 工具生成的工具站',url:'/d/6a18771a6a045c77606a5675475e616a01126104',},{title:'技术栈选择: Java 还是 Python',url:'/d/2878683b6a045c77606a5675475d616a083a1603',},{title:'请问下 github 上有没有哪个 Python 项目使用了 langchain 对接目前市面上所有的大模型的',url:'/d/1c3e743c6a045c77606a56744e5e626a3e050927',},{title:'用 PyQt 搞了个日历笔记本',url:'/d/0d11435b6a045c77606a56744f50626a0e081434',},{title:'为什么 vue 的 nuxt.js 不跟进 nextjs 的 app route 目录结构',url:'/d/02116a1e6a045c77606a56744f516a6a1b02141e',},{title:'Vite 开发服务器路径遍历漏洞(CVE-2025-30208)',url:'/d/2f2f0a2b6a045c77606a56744f5a646a231a021b',},{title:'做定时任务,一定要用这个神库!',url:'/d/2a1a550b6a045c77606a56744f5b626a5c151613',},{title:'XUGOU - 轻量级系统监控平台,基于 CloudFlare 零成本部署!',url:'/d/0a21430f6a045c77606a56744f58656a0f741e25',},{title:'NextJS 超瓜皮漏洞,赶紧升级!',url:'/d/03226a096a045c77606a56744258646a59126264',},{title:'为什么 Python 、Node.js 就不能学习一下 C#这种优雅的依赖管理方式?',url:'/d/0f1f5f3d6a045c77606a5674445c676a04311f60',},{title:'求助!双显卡连接 6 个屏幕,展示不同的 URL 页面。Electron 的 displayId 每次重启都会变',url:'/d/1f3158176a045c77606a56744551676a24111b3b',},],} const App={setup(){const goTo=useGoTo() const{mdAndUp}=useDisplay() return{goTo,mdAndUp}},data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)} if(this.nav.post.total>(this.nav.post.currentPage-1)*100+20){let moreLen=100 if(this.nav.post.total({id:null,num:(this.nav.post.currentPage-1)*100+v,uid:null,content:null,ipRegion:null,updatedByUid:null,createdAt:null,updatedAt:null,mentionNum:null,mentionedBy:null,mentionUsers:null,likeUsers:null,})) this.posts.push(...morePosts.slice(20))} this.workerStart() const hash=window.location.hash const match=hash.match(/#(\d+)/) if(match){const n=parseInt(match[1],10) if(n>=(this.nav.post.currentPage-1)*100&&n{this.jumpTo(n)})}} this.$nextTick(()=>{this.addHeadingIds() tocbot.init({tocSelector:'.toc',contentSelector:'#post-content-0',headingSelector:'h2, h3, h4',headingsOffset:100,scrollSmoothOffset:-100,scrollSmooth:true,collapseDepth:6,onClick:function(e){setTimeout(()=>{history.replaceState(null,'',window.location.pathname+window.location.search)},0)},}) tocbot.refresh()});},beforeUnmount(){this.workerStop() if(this.quill){this.quill.destroy() this.quill=null}},computed:{dposts(){return this.posts.slice(20);},},created(){},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},toPage(){let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,this.nav.post.targetPage>1?`/${this.nav.post.targetPage}`:'') window.location.href=url},toLoadRelated({done}){if(this.my&&this.my.uid){this.apiLoadRelated({done})}else{done('ok')}},workerStart(){this.nav.post.worker=setInterval(()=>{this.workerLoad()},500);},workerStop(){if(this.nav.post.worker){clearInterval(this.nav.post.worker);this.nav.post.worker=null;}},async jumpTo(num){const page=Math.floor(num/100)+1 const i=num-(page-1)*100 if(page===this.nav.post.currentPage){this.goTo("#post-"+num,this.nav.post.goToOptions) if(!this.posts[i].id){const block=Math.floor(num/20)+1 this.nav.post.apiLock[block]=true await this.apiLoadPosts(block) this.$nextTick(()=>{this.goTo("#post-"+num,this.nav.post.goToOptions)})}}else{let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,page>1?`/${page}`:'') url=url+"#"+num window.location.href=url}},postIntersect(num){return(isIntersecting,entries,observer)=>{if(isIntersecting){this.nav.post.task.push(num) this.nav.post.active.push(num) this.nav.post.active=this.nav.post.active.filter(item=>Math.abs(item-num)<=5) this.nav.post.active.sort((a,b)=>a-b)}else{this.nav.post.active=this.nav.post.active.filter(item=>item!==num)} if(this.nav.post.active[0]){this.nav.post.anchor=this.nav.post.active[0]}else{this.nav.post.anchor=0}}},async apiLoadPosts(block){try{const response=await axios.post('/fapi/v1/post/block/'+block,{discussionId:this.nav.post.discussionId,}) if(response.data.code===0){response.data.data.posts.forEach(post=>{const i=post.num%100 Object.assign(this.posts[i],post)}) response.data.data.users.forEach(user=>{this.usersMap.set(user.uid,user)})}else{this.failureAlert('回帖数据加载失败: '+response.data.msg)}}catch(error){this.failureAlert('回帖数据加载失败: '+error)} this.nav.post.apiLock[block]=false},workerLoad(){while(this.nav.post.task.length){const num=this.nav.post.task.pop() const i=num-(this.nav.post.currentPage-1)*100 if(!this.posts[i].id){const block=Math.floor(num/20)+1 if(!this.nav.post.apiLock[block]){this.nav.post.apiLock[block]=true this.apiLoadPosts(block)}}}},getTimeInfo(t){if(!t){return ""} const now=new Date();const then=new Date(t);const diff=now-then;const minute=60*1000;const hour=minute*60;const day=hour*24;const month=day*30;const year=month*12;if(diffpost.num===num) if(!post){return "#"+num} const uid=post.uid const username=this.usersMap.get(uid)?.username if(!username){return "#"+num} return username},getUsernameByPostId(id){const post=this.posts.find(post=>post.id===id) if(!post){return "#"+this.getPostNumByPostId(id)} const uid=post.uid const username=this.usersMap.get(uid).username if(!username){return "#"+this.getPostNumByPostId(id)} return username},getPostNumByPostId(id){const post=this.posts.find(post=>post.id===id) return post.num},getPostById(id){const post=this.posts.find(post=>post.id===id) return post},getPostByNum(num){const post=this.posts.find(post=>post.num===num) return post},getAvatarByUid(uid){const avatar=this.usersMap.get(uid)?.avatar if(!avatar){return this.getRandomAvatar()} return avatar},getAvatarByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post){return this.getRandomAvatar()} const uid=post.uid return this.getAvatarByUid(uid)},getRandomAvatar(){const num=Math.floor(Math.random()*100) return "https://randomuser.me/api/portraits/men/"+num+".jpg"},getUrlByUid(uid){const url=this.usersMap.get(uid)?.url if(!url){return ""} return url},getTextByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post||!post.content){return '点击跳转到#'+num+'查看'} const parser=new DOMParser() const doc=parser.parseFromString(post.content,'text/html') const text=doc.body.textContent||'' return text.slice(0,100)},addHeadingIds(){const content=document.getElementById('post-content-0') if(!content){this.nav.showTOC=false return} const headings=content.querySelectorAll('h2, h3, h4') headings.forEach((heading,index)=>{if(!heading.id){heading.id=`toc-nav-${index}`}}) if(headings.length==0){this.nav.showTOC=false}},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},debounce(fn,delay){let timer=null return function(...args){if(timer)clearTimeout(timer) timer=setTimeout(()=>{fn.apply(this,args)},delay);};},},watch:{'nav.post.targetPage':{handler:async function(newV,oldV){this.toPage()},immediate:false},},} const vuetify=createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")