软件工程2021:第2次作业—— 谈谈鸿蒙操作系统

一、鸿蒙操作系统的简介

 


 

  • 开发背景

美国将华为列入“实体清单”后,谷歌宣布将终止继续向华为提供GMS服务,于是华为将早已有所设想的HarmonyOS推到台前,并且在2020.9.10推出HarmonyOS 2.0。

  • 需求

鸿蒙系统将目光集中到了物联网这一领域,为后续鸿蒙系统生态奠定基础。

突破技术封锁,搭建独立的操作系统。

  • 开发历史

(图片来源:https://xueqiu.com/4110094713/180932847 作者:通通有讲)

  • 应用场景

物联网中的主要领域,如智能手机、自动驾驶、智能家电、智能工业等。

  • 发展趋势

  主要向物联网方向发展,对标华为提出的“1+8+N”战略,与传统企业加深合作以此在各个领域推广鸿蒙操作系统,创建鸿蒙系统生态。目前鸿蒙系统还是在ASOP代码基础上创建的系统,主要是为了兼容已有的安卓设备和贴合安卓用户的使用习惯,并且能有效缓解外部封锁压力。而之后是否会彻底抛弃ASOP则取决于鸿蒙系统生态能搭建到何种程度,规模和影响力能否大到其他厂商愿意为了鸿蒙系统单独开发软件和设备。

 

二、关于鸿蒙是否套壳的争议


 

  • 什么是创新

  我们首先来看创新的定义:创新是指以现有的思维模式提出有别于常规或常人思路的见解为导向,利用现有的知识和物质,在特定的环境中,本着理想化需要或为满足社会需求,而改进或创造新的事物、方法、元素、路径、环境,并能获得一定有益效果的行为。鸿蒙操作系统是在ASOP(安卓开源项目)这一已有的项目的基础上,摆脱了谷歌的GMS服务,利用自己的技术创建了能满足日常使用情况下的鸿蒙操作系统。而华为也是这一项目中的成员之一,因此没有侵权和套壳的说法,只能算是还无法完全摆脱ASOP。而且鸿蒙系统与安卓系统不同,鸿蒙系统的主要目标是物联网,最初的设想就是推出一个能在所有设备上都能运行的系统,智能手机只是一个起步,这一点也与现有的安卓不同。

  并且鸿蒙系统有以下几大技术特性(摘自OpenHarmony开源项目 https://gitee.com/openharmony):

  ①通过分布式软总线、分布式数据管理、分布式任务调度、设备虚拟化这几个模块实现硬件互助,资源共享。

  ②一次开发,多端部署。能够保证开发的应用在多终端运行时保证一致性。

  ③统一OS,弹性部署。做到硬件资源的可大可小,在多种终端设备间,按需弹性部署。

  以上这些特性都是鸿蒙系统基于目前物联网领域的需求所开创的创新特性。

  • 代码复用与创新的关系

  代码复用不等于抄袭,不等于原样照搬,代码复用是在原有代码的基础上扩展自己的内容,两者并不冲突。代码复用的主要目的是利用已有的优秀的高效的代码或模块,为自己的开发创造便利,提高代码编写的效率和质量。你不能因为我使用了某些已有的算法,借鉴了某些成功的代码编写模式,就认为我整个项目毫无创新,只有抄袭。跳出代码这个层面,目前很多仿生学案例都是源于已有的生物特性和模式并加以现代的技术完成的创新以此来达到目的,那是否就不算创新了呢?显然不能以复用来评判创新与否。总而言之,代码复用是一种方式和手段,而创新是目的,利用手段达到目的没有任何的问题。

 

三、代码风格分析


 

1. 好的代码风格1:

    • 代码(截取部分):
/*
    Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

package com.huawei.industrydemo.shopping.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.huawei.industrydemo.shopping.entity.AppConfig;

/**
 * @version [Ecommerce-Demo 1.0.2.300, 2021/3/19]
 * @see [Related Classes/Methods]
 * @since [Ecommerce-Demo 1.0.2.300]
 */
@Dao
public interface AppConfigDao {

    /**
     * Query a value based on keyword.
     * 
     * @param keyword keyword
     * @return value
     */
    @Query("SELECT value FROM AppConfig WHERE (keyWord=:keyword)")
    String getValue(String keyword);

    /**
     * Insert or update a configuration item.
     * 
     * @param appConfig AppConfig
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void addValue(AppConfig appConfig);

}
    • 分析:有该段代码的使用规范,版本等信息。代码注释完整,提供了完备的注释,排版合理。

2.好的代码风格2:

    • 代码(截取部分):
package tk.winshu.shortestpath.algorithm;

import tk.winshu.shortestpath.model.Node;

import java.util.*;

/**
 * Dijkstra算法
 * <p>
 * <a href="https://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html">最短路径—Dijkstra算法和Floyd算法</a>
 *
 * @author winshu
 * @date 2015年2月5日
 */
public class Dijkstra {

    private Set<Node> openNodes;
    private Set<Node> closeNodes;
    /**
     * 用于存放节点到 source 节点的距离
     */
    private Map<Node, Integer> distances;
    private Map<Node, Node> predecessors;

    /**
     * 是否有向图
     */
    private boolean isDirectedGraph;

    /**
     * @param isDirectedGraph 是否有向图
     */
    public Dijkstra(boolean isDirectedGraph) {
        this.isDirectedGraph = isDirectedGraph;
        this.openNodes = new HashSet<>();
        this.closeNodes = new HashSet<>();
        this.distances = new HashMap<>();
        this.predecessors = new HashMap<>();
    }

    public void preProcess(Node source) {
        this.openNodes.clear();
        this.closeNodes.clear();
        this.distances.clear();
        this.predecessors.clear();

        // source -> source : distance = 0
        distances.put(source, 0);
        openNodes.add(source);

        while (!openNodes.isEmpty()) {
            // 获取最短路径的节点
            Node node = pickMinimumDistanceNode();
            // 将该节点加入已处理集合中
            closeNodes.add(node);
            // 将该节点从未处理集合中移除
            openNodes.remove(node);
            // 查找最短距离并更新
            processMinimalDistances(node);
        }
    }
    • 分析:提供了代码相关的链接,给出了充分的代码注释,并且符合起名规则,可读性强,排版合理。

3.不好的代码风格1:

    • 代码(截取部分): 
import java.util.Scanner;

public class feng1 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i1 = sc.nextInt();
        int i2 = sc.nextInt();
        int i3 = sc.nextInt();
        int i4 = sc.nextInt();
        int i5 = sc.nextInt();
        Point p1 = new Point(i1,i2);
        Point p2 = new Point(i3);
        System.out.println(String.format("%.2f",p1.distance()));
        System.out.println(String.format("%.2f",p2.distance()));
        System.out.println(String.format("%.2f",p1.distance(i4,i5)));
        System.out.println(String.format("%.2f",p1.distance(p2)));
    }
   
}
class Point{
    int heng;
    int zong;
    public Point(){

    }
    public Point(int x,int y){
        heng=x;
        zong=y;
    }
    public Point(int x){
        heng=x;
        zong=x;
    }
    public double distance(){
        double dist =0;
        dist = heng*heng+zong*zong;
        dist = Math.pow(dist,0.5);
        return dist;
    }
    public double distance(int x,int y){
        double dist=0;
        dist = (heng-x)*(heng-x)+(zong-y)*(zong-y);
        dist = Math.pow(dist,0.5);
        return dist;
    }
    public double distance(Point other){
        double dist=0;
        dist = (heng-other.heng)*(heng-other.heng)+(zong-other.zong)*(zong-other.zong);
        dist = Math.pow(dist,0.5);
        return dist;
    }
} 
    • 分析:整段代码没有一个注释,可读性不好。其次类名称“feng1”起的很随意,只看类名完全不知道是什么意思,也不符合驼峰起名法。起名随意还表现在变量的名字上,“heng”,“zong”明显使用了拼音来命名,不推荐。
posted @ 2021-09-12 17:22  爱吃猫的_鱼  阅读(90)  评论(0编辑  收藏  举报