Object Orientation is not a Goal

本文探讨了软件开发的本质,指出开发的目的是解决问题而非追求特定的编程范式。作者认为每种编程范式都有其适用场景,开发者应根据实际需求选择合适的工具和技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:

http://java.dzone.com/news/object-orientation-not-goal

 

 

I frequently read or hear people say something along the lines of "this or that is not properly object oriented", or "... function oriented", or something else similar to that. I used to utter the same statements, when I first came out of university. This kind of statement was also present in the article published here yesterday, titled "what we don't need in object oriented programming". 

 

Later, in the real world, I learned the shocking truth:

 

We do not develop software to make it object oriented, or to comply with any other paradigm.

We develop software to solve problems.

 

Each programming paradigm (OO, FOP, AOP etc.) is great at solving a specific type of problems, but none of them, in my opinion, is the best at everything. Therefore, I appreciate being given the choice of tools and language constructs, rather than having them dictated to me. What kind of tools or constructs I need depends on what kind of problem I am trying to solve.

For instance, why is it that in 2010, Java still doesn't have unsigned primitive types? Whenever I find myself having to do bit manipulation, I get annoyed by this. Why have I not been given the choice of what kind of primitives to use?

Along the same line, why does Scala only have object types? If I am trying to develop some software that works on binary data, I don't want Scala to optimize for me behind the scenes. I want to control it myself. If I have to do bit manipulation of large amounts of binary data, why is it, that Scala's primitive types are immutable? So, for every manipulation I create a new instance of the type? Lame.

In general, it bothers me to see elitist developers make limiting decisions on my behalf, without knowing what problem I am trying to solve. It's like saying "We know better than you what you need, so we will prohibit this or that tool / style / construct". But the thing is, such elitist thinker do NOT know better than the individual developer, what tools or constructs he or she needs to solve a given problem. To make an analogy, this is exactly like elitist politicians who think they know best how everybody should live their lives... 

To sum it up: We develop software to solve problems, and whatever it takes to solve a given problem properly, is the "right" way of doing it. At the moment, it seems to me that the only language design camp that really gets this, is the C# team. And I'm a Java fan with 11 years of Java under my belt, so it hurts to say this. It just seems to me, that they are the only language designers that truly acknowledges the fact, that I don't need to be forced to use a certain paradigm, but be given the choice myself.

改进以下代码使其更快 #! /usr/bin/env python # @Source: https://www.guyuehome.com/35146 # @Time: 2023/10/20 17:02:46 # @Author: Jeff Wang(Lr_2002) # LastEditors: sujit-168 su2054552689@gmail.com # LastEditTime: 2024-03-22 10:23:42 import os import rospy, rospkg import actionlib # 引用 actionlib 库 import waypoint_race.utils as utils import move_base_msgs.msg as move_base_msgs import visualization_msgs.msg as viz_msgs class RaceStateMachine(object): def __init__(self, filename, repeat=True): """ init RaceStateMachine filename: path to your yaml file reapeat: determine whether to visit waypoints repeatly(usually True in 110) """ self._waypoints = utils.get_waypoints(filename) # 获取一系列目标点的值 action_name = 'move_base' self._ac_move_base = actionlib.SimpleActionClient(action_name, move_base_msgs.MoveBaseAction) # 创建一个 SimpleActionClient rospy.loginfo('Wait for %s server' % action_name) self._ac_move_base.wait_for_server self._counter = 0 self._repeat = repeat # 以下为了显示目标点: self._pub_viz_marker = rospy.Publisher('viz_waypoints', viz_msgs.MarkerArray, queue_size=1, latch=True) self._viz_markers = utils.create_viz_markers(self._waypoints) def move_to_next(self): pos = self._get_next_destination() if not pos: rospy.loginfo("Finishing Race") return True # 把文件读取的目标点信息转换成 move_base 的 goal 的格式: goal = utils.create_move_base_goal(pos) rospy.loginfo("Move to %s" % pos['name']) # 这里也是一句很简单的 send_goal: self._ac_move_base.send_goal(goal) self._ac_move_base.wait_for_result() result = self._ac_move_base.get_result() rospy.loginfo("Result : %s" % result) return False def _get_next_destination(self): """ determine what's the next goal point according to repeat """ if self._counter == len(self._waypoints): if self._repeat: self._counter = 0 else: next_destination = None next_destination = self._waypoints[self._counter] self._counter = self._counter + 1 return next_destination def spin(self): rospy.sleep(1.0) self._pub_viz_marker.publish(self._viz_markers) finished = False while not rospy.is_shutdown() and not finished: finished = self.move_to_next() rospy.sleep(2.0) if __name__ == '__main__': rospy.init_node('race') package_name = "tianracer_gazebo" # Get the package path try: pkg_path = rospkg.RosPack().get_path(package_name) # Construct the path to scripts directory filename= os.path.join(pkg_path, "scripts/waypoint_race/points.yaml") print(f"yaml: {filename}") except rospkg.ResourceNotFound: rospy.logerr("Package '%s' not found" % package_name) exit(1) filename = rospy.get_param("~filename",filename) repeat = rospy.get_param('~repeat', True) m = RaceStateMachine(filename, repeat) rospy.loginfo('Initialized') m.spin() rospy.loginfo('Finished')
06-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值