DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: laidabin
今日帖子: 6
在线用户: 21
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/11/26 13:01:24
标题:
如何让代码更乱套的技巧 浏览:1573
加入我的收藏
楼主: 1:

TVery_Very_Very_Long_Name=class
  procedure Hello;
end;

implementation
type
  ShortName= TVery_Very_Very_Long_Name;

procedure ShortName.Hello;
begin
end;

//////////

2:

procedure test;
type
  t=TVery_Very_Very_Long_Name;
var
  x:t;
begin
  x:=t.create;
  x.hello;
end;
----------------------------------------------
z@S7
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/26 22:03:12
1楼: I dont see nothing!
just a inheriting in many places!
in fact, "words / names" nothing means to computers! only for human!
at end, all is bits! 0 and 1

ShortName is an "ALIAS" to long_names
ShortName.Hello "would can hides if was inheriting not overrided"  long_names....procedure
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/11/27 15:56:09
2楼: @emailx45

Yes ,that is nothing to computer, but always make my brain and eye balls pain .....

And,what do you think with below codes ?

type
  TTypeA=class
    class function A:String;
  end;

  TTypeB=class
    class function B:string;
  end;

  TTypeC=record
    Data:String;
  end;

  TypeX=class
    type
    TypeA=TTypeA;
    TypeB=TTYpeB;
    TypeC=TTypeC;
  end;

procedure test;
type
  xc=TypeX.TypeC;
var
  x,y:string;
  z:xc;
begin
  x:=TYpeX.TypeA.A;  
  y:=TypeX.TypeB.B;
  z.data:='TypeXTypeC';
end;
----------------------------------------------
z@S7
作者:
男 yxsoft (yxsoft) ★☆☆☆☆ -
盒子活跃会员
2022/11/27 20:32:33
3楼: Actually i use the similar codes in some cases that i would not talk the reason.
----------------------------------------------
Great!
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/28 1:13:45
4楼: Since such code is, in fact, bad, and it indicates that the programmer is not a programmer, but a would-be candidate for a programmer vacancy in a computer science entrance exam, then,....

 I would say, without any arrogance , that:

--- do not use something like that! --- Unless you want to play crazy at certain moments in your life, (without using illicit intoxicants).

Sumary:  this code is nothing, at all! confuse and unnecessary!


type
  TTypeA = class
    class function A: String; // this function belongs to "class" of of type!!! not to the object/instance!!!
  end;

  TTypeB = class
    class function B: String; // this function belongs to "class" of of type!!! not to the object/instance!!!
  end;

  TTypeC = record
    Data: String;
  end;

  TypeX = class
  // all "new" types is "PUBLIC" in this class! ==> it's "ALIASes" from "real-TYPES above"... nothing more!
  type
    TypeA = TTypeA; // TRY VERIFY THE "POINTER" ON MEMORY IF THE SAME OR NOT (IF NOT ASSIGNED ANY VALUE BEFORE)
    TypeB = TTypeB;
    TypeC = TTypeC;
  end;

procedure test;
type
  xc = TypeX.TypeC;
var
  x, y: String;
  z   : xc;
begin
  x      := TypeX.TypeA.A; // just "getting" a "string-value" produced in "A function"
  y      := TypeX.TypeB.B;
  z.Data := 'TypeXTypeC'; // just storing a string
end;

{ TTypeA }

class function TTypeA.A: String;
begin

end;

{ TTypeB }

class function TTypeB.B: String;
begin

end;

end.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/28 1:20:05
5楼: start from:

use "names" that explains your usage, and type!
----------
type
   TCustomerName = string;

var
   LCustomerID : integer;  = integer type to "customer IDs'

function GetCustomer(const AID:string):TCustomerName; // accept only a "string", understanding is "ID" (as string) from customer
begin
  result := '....'; // result in "string", understanding that is "customer name"
end;

NOTE: you can use any name, any type, that "IT DONT CONFLICT WITH INTERNAL USAGE FROM LANGUAGE"!!!

what is better here?

var
   iMyVar : integer;
   LMyVar : integer;
   scMyVar : integer;
   CustomerID:integer;

...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/28 1:29:42
6楼: try this:

{ TTypeA }

class function TTypeA.A: String;
begin
  result := 'hello';
end;

{ TTypeB }

class function TTypeB.B: String;
begin
  result := 'world';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  MyTTypeA: TTypeA;
  MyTypeA : TypeX.TypeA;
begin
  ShowMessage(          { }
    integer(MyTTypeA).ToString + ' -- ' + { 1 position }
    integer(MyTypeA).ToString          { other position }
    );
  //
  ShowMessage(          { }
    MyTTypeA.A + ' -- ' + { hello }
    MyTypeA.A          { hello }
    );
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/11/28 10:31:13
7楼: @yxsoft ,Thanks for your reply .
@emailx45,Thanks a lot for your suggestion.

All above codes I wrote was start from human side view ,about to organize types define in many units(.pas).

When  I have Unit_A.Type1..Type10, Unit_Z.Type_991...Type...999(like some orm class defines stage),
Under normal conditions, I will write Uses Unit_A,...Unit_Z to use them.

So I consider to define a Unit_0.Type_?,  and define type alias to all other types in other units.

likes a tree

Unit_0;
  Type_?=class
  type
     Type_1=Unit_A.Type_1;
     ...
     Type_999=Unit_Z.Type_999;
  end;

or 

Unit_0;
  Type_?=class
  type
    Catalog_A=class
    type
      Type_1=Unit_A.Type_1;
      ...
    end;
    ... 
    Catalog_Z=class
    type
      ...
      Type_999=Unit_Z.Type_999;
    end;
  end;

So,i can just "uses unit_?" when i want use these types (with Code Insight);


After learned :

from floor 1
  Type Alias Like "TypeA=TypeB", Method of "TypeA"  "would can hides if was inheriting not overrided"
from floor 6 
  "MyTTypeA" and "MyTypeA" is not same position (in memory ?).

I will re-consider it;

@@emailx45, thanks again;
----------------------------------------------
z@S7
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/28 11:25:08
8楼: Honestly, your way of "seeing things" is, at the very least, a mistake!

Even Embarcadero units don't use that many types in their declarations.
And, having 1000 types defined is something you should never dream of wanting! = 1000.DCus in disk!!!

Just remembering that, when defining this type of usage, you will be compiling all the referenced units. Even use it only one or two!

I think you're heading for chaos! Think about it!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 dalas (dalas) ★☆☆☆☆ -
普通会员
2022/11/28 13:09:46
9楼: 为什么要让代码更乱套?是想将住继任者还是要把自己逼疯?
----------------------------------------------
-
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/11/28 13:26:00
10楼: 这是个见仁见智的问题……,可能是有意的,也可能是无意的。

Type Alias到底会造成什么样的混乱,我也不确定,因为从我自身角度出发,我更希望能快速的选取到所需要的类来使用,而不是在需要的时候,把多个单元的定义都再过滤一遍,尤其是那种数据对象类。
----------------------------------------------
z@S7
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/28 23:11:07
11楼: I'm getting out of here!
I was overcome by an intelligence greater and far superior to mine!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/11/29 5:37:19
12楼: @emailx45
"见仁见智" -> "仁者见仁,智者见智"
是一个 汉语成语 ,拼音是 rén zhě jiàn rén zhì zhě jiàn zhì,比喻因个体差异,对事物就会有不同的看法。 出自《 周易 》。 常用义:仁者从仁的角度看待,智者从智的角度看待。 比喻对同一个问题,不同的人从不同的立场或角度去看有不同的看法。 本义:不同的人从不同角度去认识事物,有如佛家明心见性,心中有仁者就从仁的角度去考察发掘事物仁的一面,智者就从智的一面去考察发掘事物智慧的一面。

This "见仁见智" is the simple version of Chinese Idioms "仁者见仁,智者见智",it come from 《Zhou Yi》 , means different person see the same thing from different point of view. this word is no means "who is much much intelligence greater and far superior  than others".

It is "neutral word"(中性词), not just from the word itself(字面意义).
I use this word to explain to @dalas "why someone  make codes into chaos."


I hope to explain this word will not make things turn into another chaos ......
----------------------------------------------
z@S7
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/11/29 8:16:34
13楼: I only said that: my mind cannot follow the proposed train of thought!
-- translating: I can't imagine the practical use of this elaboration!

I see that perspectives are closely related to the position in which the observer is. So I can't find this observation point.

And therefore, I prefer to leave the room so as not to occupy a place that does not belong to me.

Anyway, point of view is always tricky to debate!
But if it's ok for all parties, then ok!

Note: any translation errors are GOOGLE's fault... not mine!  :_)))
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行62.5毫秒 RSS