韩磊之走入C#面向对象误区!

本文讨论了通过手写Windows应用程序而非使用IDE提供的控件来评估程序员对面向对象编程理解的做法,并提出了一些观点认为这种方法可能并非最佳途径。

最近,韩磊翻译的一本书:C#面向对象-概念到代码之路。

其中在序言中说了一件很有趣的事情:他面试程序员的时候,要别人直接写windows小应用程序,而不用IDE提供的控件。他的意思是说,很多人使用C#但是不理解面向对象的思想。的确,C#是完全面向对象的优秀语言,在每个地方都体现了面向对象,所以 你不要别人拖放控件直接写控件的委托和实践,其实并非是在考别人是否理解面向对象编程,而是在考别人到底对IDE的模板以及.net对象的记忆理解程度而已。

其实他这种做法也并不新鲜,有其它公司也把Java拿出来,让程序员脱离IDE环境直接写图形界面程序,这就需要 程序员努力记忆那些常用控件的使用。当然在windows 应用程序模板中,就直接在构造函数调用了控件类的创建和使用,说实话,也是非常简单的事情,当然难就难在你理解使用委托来实现事件的原理。不过对于编制了很多程序的程序员来说,这点并非难事。

继续说说韩磊这样倡导无IDE开发环境的编程尽管有一定的意义,但是实际上不可取的。我们这些工作了20年的老程序员在开始苹果Basic之路的时候,就深深知道,程序开发环境能提供的功能越高越好,提供的代码越简单越好,甚至包括了服务程序和驱动程序能直接给我们接口那就更好了。菜单以前需要我们去编制,现在直接把控件一拖就可以了,我们不必要再回到C++的MFC时代,我们普通程序甚至不需要去了解类中封装的代码,你就直接使用属性和方法好了。

韩磊这样倡导的事情,还不如倡导大家去把System.object都去读一遍,背下来,兴许更容易理解怎么去编程序哦,更容易理解怎么去建一座超级的高楼,但是我们是没有必要的,没有必要去花费这个精力,程序员的精力是有限的,没有必要投入 到无限的有用的破解黑箱里去。

不过大家关心一下IDE提供的模板程序,这个是不错的,但是必要去亲身写,当然作为学习是可以的,甚至不学这些可以拖拉的控件也不影响你使用委托和事件。在很多应用程序中,会迫使你去使用委托和事件的。

韩磊的观点,只不过太牵强了,完全是一种吵作的无用理论。

 

 

<template> <div class="about-page-container"> <!-- 小组成员标题 --> <div class="team-header"> <h1 class="team-title">农大熬夜秃头组</h1> <img src="@/assets/logo.png" alt="Logo" class="group-logo" /> </div> <!-- 内容容器 --> <div class="content-container"> <!-- 左侧:小组成员部分 --> <div class="team-members"> <div class="member-list"> <div class="member-item" v-for="(member, index) in teamMembers" :key="index"> <img :src="member.avatar" :alt="member.name" class="member-avatar" /> <div class="member-info"> <p class="member-name">{{ member.name }}</p> <p class="member-email" @click="copyEmail(member.email)"> {{ member.email }} </p> </div> </div> </div> </div> <!-- 右侧:圆盘时钟部分 --> <div class="clock-container"> <div id="clock"> <div class="hand hour-hand" :style="{ transform: `rotate(${hourDegrees}deg)` }"></div> <div class="hand minute-hand" :style="{ transform: `rotate(${minuteDegrees}deg)` }"></div> <div class="hand second-hand" :style="{ transform: `rotate(${secondDegrees}deg)` }"></div> <!-- 时钟中心点 --> <div class="center-point"></div> <!-- 时钟刻度点 --> <div v-for="(angle, index) in clockMarkAngles" :key="'mark-' + index" class="clock-mark" :class="{ 'big-mark': [0, 3, 6, 9].includes(index), 'small-mark': ![0, 3, 6, 9].includes(index) }" :style="{ transform: `translate(-50%, -50%) rotate(${angle}deg) translate(0, -200px)` /* 调整刻度位置 */ }" ></div> </div> </div> </div> </div> </template> <script setup lang="ts"> import { ref, computed, onMounted } from 'vue'; // 导入头像图片资源(根据实际路径调整) import avatar1 from '../assets/avatar1.png'; import avatar2 from '../assets/avatar2.png'; import avatar3 from '../assets/avatar3.png'; import avatar4 from '../assets/avatar4.png'; import avatar5 from '../assets/avatar5.png'; import avatar6 from '../assets/avatar6.png'; // 小组成员数据 const teamMembers = [ { name: '韩磊大帅锅', email: '2815984077@qq.com', avatar: avatar1 }, { name: '球球小可爱', email: '3027830960@qq.com', avatar: avatar2 }, { name: '. ', email: '3503429197@qq.com', avatar: avatar3 }, { name: 'Zui_ren', email: '2036382099@qq.com', avatar: avatar4 }, { name: '梁哲源大帅哥', email: '2064685542@qq.com', avatar: avatar5 }, { name: '00', email: '27245185689@qq.com', avatar: avatar6 }, ]; // 时钟指针角度 const hourDegrees = ref(90); const minuteDegrees = ref(90); const secondDegrees = ref(90); // 计算时钟刻度的角度(0-11小时对应的角度) const clockMarkAngles = computed(() => { return Array.from({ length: 12 }, (_, i) => i * 30); }); // 更新时钟函数(使用北京时间) const updateClock = () => { const now = new Date(); // 获取当前时间 const utcOffset = 8; // 北京时间偏移量(+8小时) const beijingTime = new Date(now.getTime() + now.getTimezoneOffset() * 60000 + utcOffset * 3600000); const seconds = beijingTime.getSeconds(); const minutes = beijingTime.getMinutes(); const hours = beijingTime.getHours(); secondDegrees.value = ((seconds / 60) * 360) + 90; minuteDegrees.value = ((minutes / 60) * 360) + ((seconds / 60) * 6) + 90; hourDegrees.value = ((hours % 12) / 12) * 360 + ((minutes / 60) * 30) + 90; }; // 复制邮箱地址 const copyEmail = (email: string) => { navigator.clipboard.writeText(email).then(() => { alert('邮箱已复制到剪贴板'); }).catch(err => { console.error('无法复制邮箱: ', err); }); }; // 挂载后启动时钟更新 onMounted(() => { setInterval(updateClock, 1000); updateClock(); // 初始化时钟 }); </script> <style scoped> /* 颜色变量 */ :root { --primary-color: #409eff; --secondary-color: #67c23a; --accent-color: #e6a23c; --text-color: #333; --light-text-color: #666; --bg-color: #f5f7fa; --border-color: #e4e7ed; } /* 整体页面容器 */ .about-page-container { min-height: 100vh; display: flex; flex-direction: column; background-color: #f9fafc; font-family: 'Inter', sans-serif; padding: 20px; } /* 小组成员标题 */ .team-header { display: flex; justify-content: center; align-items: center; margin-bottom: 40px; gap: 15px; } .team-title { font-size: 32px; font-weight: 600; color: var(--text-color); margin: 0; } .group-logo { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; border: 2px solid var(--primary-color); background-color: #fff; } /* 内容容器 */ .content-container { display: flex; justify-content: space-between; /* 确保左右两侧分开 */ gap: 40px; flex-wrap: wrap; /* 在小屏幕上换行 */ } /* 左侧:小组成员部分 */ .team-members { flex: 1; /* 占据左侧空间 */ max-width: calc(50% - 40px); /* 略小于两个时钟组件的高度 */ } .member-list { display: flex; flex-direction: column; gap: 20px; } .member-item { display: flex; align-items: center; padding: 10px; /* 缩小卡片尺寸 */ background-color: white; border-radius: 15px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); transition: transform 0.3s ease; font-size: 14px; /* 调整字体大小以适应缩小的卡片 */ } .member-item:hover { transform: translateY(-5px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12); } .member-avatar { width: 60px; /* 缩小头像尺寸 */ height: 60px; border-radius: 50%; object-fit: cover; margin-right: 15px; border: 2px solid var(--primary-color); } .member-info { display: flex; flex-direction: column; flex-grow: 1; } .member-name { font-size: 16px; /* 调整名称字体大小 */ font-weight: 600; color: var(--text-color); margin: 0 0 5px 0; } .member-email { font-size: 12px; /* 调整邮箱字体大小 */ color: var(--light-text-color); cursor: pointer; display: flex; justify-content: center; align-items: center; gap: 5px; padding: 3px 8px; /* 缩小内边距 */ background-color: #f0f7ff; border-radius: 20px; width: fit-content; transition: all 0.3s ease; } .member-email:hover { color: var(--primary-color); background-color: #e1edff; } /* 右侧:圆盘时钟部分 */ .clock-container { flex: 1; /* 占据右侧空间 */ max-width: 40%; /* 调整为略小的比例 */ display: flex; justify-content: center; align-items: center; } #clock { width: 400px; /* 调整为较小的尺寸 */ height: 400px; background: radial-gradient(circle, #ffffff 0%, #f5f7fa 100%); border: 16px solid var(--primary-color); /* 调整边框宽度 */ border-radius: 50%; position: relative; display: flex; justify-content: center; align-items: center; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1), inset 0 0 10px rgba(0, 0, 0, 0.05); } .hand { position: absolute; bottom: 50%; transform-origin: center bottom; transition: transform 0.05s cubic-bezier(0.1, 2.7, 0.58, 1); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); border-radius: 6px; } .hour-hand { width: 12px; height: 120px; /* 缩短指针长度 */ background: linear-gradient(to bottom, #90ee90 0%, #70cc70 100%); /* 浅绿色 */ top: 80px; z-index: 3; } .minute-hand { width: 8px; height: 160px; /* 缩短指针长度 */ background: linear-gradient(to bottom, #ffffe0 0%, #ffffb3 100%); /* 浅黄色 */ top: 60px; z-index: 4; } .second-hand { width: 4px; height: 180px; /* 缩短指针长度 */ background: linear-gradient(to bottom, #ff4d4f 0%, #d9363e 100%); top: 40px; z-index: 5; } /* 时钟中心点 */ .center-point { position: absolute; width: 20px; /* 缩小中心点 */ height: 20px; background: linear-gradient(to bottom, var(--primary-color) 0%, #3080e0 100%); border-radius: 50%; z-index: 10; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } /* 时钟刻度 - 黑色圆点样式 */ .clock-mark { position: absolute; top: 50%; left: 50%; transform-origin: center center; z-index: 2; } .big-mark { width: 10px; /* 较大的黑色圆点 */ height: 10px; background-color: black; border-radius: 50%; box-shadow: 0 0 2px rgba(0, 0, 0, 0.5); } .small-mark { width: 5px; /* 较小的黑色圆点 */ height: 5px; background-color: black; border-radius: 50%; box-shadow: 0 0 1px rgba(0, 0, 0, 0.3); } /* 响应式设计 */ @media (max-width: 1200px) { .content-container { flex-direction: column; /* 在小屏幕上垂直排列 */ } .team-members, .clock-container { max-width: 100%; /* 占据整行 */ flex: 1; } #clock { width: 300px; height: 300px; } } @media (max-width: 600px) { #clock { width: 250px; height: 250px; border-width: 12px; } } </style> 导入使用时钟组件
06-19
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caridle

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值