資料は量の制限のために要約されています。
私にとって、プログラミングはテクノロジーであるだけでなく、多くの点でアートでもあります。 したがって、コードの美しさは非常に重要です。
過去数年間、私はプログラムコードの洗練された美しさを破壊するプログラミング技術を収集してきました。
- プログラムの開始時のすべての変数の宣言。
- パラメータを介して関数の結果を返します。
- ローカル機能の欠如;
-
else if
; - ;
- ;
-
obj.getProperty()
obj.setProperty(value)
; - ;
- ;
- « ».
:
, , .
. , — , .
, , . ; , , ..
. , . , , .
— . «» ! .
— [1]. |
: ( ) ( ).
: , , ; , , .
:
: 300 [2]. - 200- . 200 ,temp
, , , 200- … -, .
, , . , Pascal/Delphi. …
:
, , .
( , ) : , .
, , :
= (1, 2)
.
, : (1, 2, &)
. . , , . |
, .
, .
:
, C++ , . .
, :
int mtxResult [10][10] = mult (mtxA, mtxB);<br><br>
, , :
mult (mtxA, mtxB, mtxResult);
, , .
:
, :
Matrix mtxResult = mult (mtxA, mtxB);
(- ), , , .
, .
:
, C++ , .a
,b
,c
:
,x1
x2
.
C++ :
intRootsCount, numX1, numX2 = quadraticEquation (numA, numb, numC)<br><br>
:
intRootsCount = quadraticEquation (numA, numB, numC, &numX1, &numX2);
, , , , .
:
[3]:
QuadrEqResult qerResult = quadraticEquation (numA, numB, numC);<br>intRootsCount = qerResult.count;<br>numX1 = qerResult.x1; <br>numX2 = qerResult.x2;
, , , : .
, C++, (. ). , , .
, , , JavaScript , .
:
function quadraticEquation (numA, numb, numC)<br> {<br> //...<br> return ({<br> count: intRootsCount,<br> x1: intX1,<br> x2: intX2<br> });<br> }<br><br>var objResult = quadraticEquation (numA, numB, numC);<br>intRootsCount = objResult.count;<br>numX1 = objResult.x1; <br>numX2 = objResult.x2; <br>
!
:
, ( -, ) (, ).
, .
, .
! , , .. , , .
, .. , — . |
:
Pascal/Delphi , , . , , , , .
:
, , .
.
… ( ) , , .
program main (); function block3 (param: integer): integer; { (4)--¬ } begin { ^ v } #3 { ^ v } end; { ^ v } {} { ^ v } procedure block5 (param: integer); { ^ v (7)--¬ } begin { ^ v ^ v } #5 { ^ v ^ v } end; { ^ v ^ v } {} { ^ v ^ v } begin { ^ v ^ v } #1 { (1) ^ v ^ v } {} { v ^ v ^ v } #2 { (2) ^ v ^ v } {} { v ^ v ^ v } { v ^ v ^ v } block3 { v ^ v ^ v } block3 (param); { (3)--- v ^ v } {} { v ^ v } #4 { (5) ^ v } {} { v ^ v } { v ^ v } block5 { v ^ v } block5 (param); { (6)--- v } {} { v } #6 { (8) } end.
? , , , , . , , , . , . , -goto
.
, «» , (JavaScript, Python), (Java). .
else if
:
.
, , . , .
, .
, , , :
, , , . , , .
1:
, , . « », « », « », « » .
, , :
if (numHour >= 0 && numHour < 6)<br> {<br> print (" !");<br> }<br>else<br> {<br> if (numHour >= 6 && numHour < 12)<br> {<br> print (" !");<br> }<br> else<br> {<br> if (numHour >= 12 && numHour < 18)<br> {<br> print (" !");<br> }<br> else<br> {<br> print (" !");<br> }<br> }<br> }<br><br>
, :
if (numHour >= 0 && numHour < 6)<br> {<br> print (" ");<br> }<br>else if (numHour >= 6 && numHour < 12)<br> {<br> print (" !");<br> }<br>else if (numHour >= 12 && numHour < 18)<br> {<br> print (" !");<br> }<br>else<br> {<br> print (" !");<br> }
2:
, , , , , , — .
, «», « » — « ». , :
if (!isRegistred ())<br> {<br> print (" . !");<br> }<br>else if (numHour >= 0 && numHour < 6)<br> {<br> print (" ");<br> }<br>else if (numHour >= 6 && numHour < 12)<br> {<br> print (" !");<br> }<br>else if (numHour >= 12 && numHour < 18)<br> {<br> print (" !");<br> }<br>else<br> {<br> print (" !");<br> }<br>
, :
if (!isRegistred ())<br> {<br> /*<br> <br> */<br> print (" . !");<br> }<br>else<br> {<br> /*<br> <br> */<br> if (numHour >= 0 && numHour < 6)<br> {<br> print (" !");<br> }<br> else if (numHour >= 6 && numHour < 12)<br> {<br> print (" !");<br> }<br> else if (numHour >= 12 && numHour < 18)<br> {<br> print (" !");<br> }<br> else<br> {<br> print (" !");<br> }<br> }<br>
(-, - - )
if
else
,
else if
. , ( №1).
,
else if
.
, , .
:
: , — .
.
-, .
, .
, , , ..
:
,lastName
,firstName
,sirName
:objPeople1
.
objPeople1.lastName = "";<br>objPeople1.firstName = "";<br>objPeople1.sirName = "";<br><br><br>
, :
doSomething (objPeople1);<br>
-, : , , ..
:
:
World.Russia.Moscow./*Kremlin*/WhiteHouse.Putin<br>
:
,
:
redBag.blueBag.myThing<br><br>
… :
blueBag.redBag.myThing
- .
- ! , .
. |
:
, : , .
:
char *lastNames [3] = {"", "", ""};<br>char *firstNames [3] = {"", "", ""};<br>char *sirNames [3] = {"", "", ""};<br>const lenin = 0, stalin = 1, khrushchev = 2;
:
//: " "<br>cout<<firstNames[khrushchev]<<" "<<lastNames[khrushchev];
.
-, . .
:
, :
doSomething(lastNames [lenin], lastNames [lenin], sirNames [lenin]);
-, «-».
:
firstNames[khrushchev]
,firstName
, , , , !
< - ...>
, .:
People *leaders [7] = <br> {<br> new People ("", "", ""),<br> new People ("", "", ""),<br> new People ("", "", ""),<br> new People ("", "", ""),<br> new People ("", "", ""),<br> new People ("", "", ""),<br> new People ("", "", "")<br> };<br><br>// – . <br>const lenin = 0, stalin = 1, brezhnev = 2, gorbachev = 6;<br><br><br>//: " "<br>cout<<leaders [lenin].firstName<<" "<< leaders [lenin].lastName;<br><br>//: " "<br>cout<<leaders [brezhnev].firstName<<" "<< leaders [brezhnev].lastName;<br><br>//: " "<br>cout<<leaders [gorbachev].firstName<<" "<< leaders [gorbachev].lastName;<br>
object.getProperty ()
object.setProperty (value)
:
, .
:
— ;
— .
, , :
:
objObject.property1 = "value1";
:
objObject.doSomething (param1, param2);
— . |
. .
, , .
-, -, .
1:
, , , :objObject.property1
intA = objObject.property1; //<br>objObject.property1 = intB; //<br>
, :objObject.getProperty1 ()
objObject.setProperty1 ()
:
intA = objObject.getProperty1 ();//<br>objObject.setProperty1 (intB); //<br>
,
++
,
+=
.
2:
1.
:
objObject.property1++;
, :
objObject.setProperty1 (objObject.getProperty1 () + 1);
, .
3:
Person
_money
, money:
class Person<br> {<br> private long _money;<br><br> public long money<br> {<br> get<br> {<br> return (_money);<br> }<br> set <br> {<br> _money = value;<br> }<br> }<br> }
:
Person psnBillGates = new Person (); lngOldRiches = psnBillGates.money; // psnBillGates.money = lngNewRiches; // psnBillGates.money += 1000000000; //
: Delphi, C#, Python, Ruby .
: C++, Java JavaScript[4]…
, , JavaScript. , . — , , JavaScript .
, JavaScript — [5].
:
,
, , .
, , .
, (, ) , , .
, ( Lisp Haskell) : , . ( ) + . , , .
.
, . — -, , , .
1:
, (), -, , .
2:
, (), , - .. 2*2.
3:
( ) . -, … 2.
, ( ) . - . , , , «», , . , . , .
, . — .
. |
, , , . , , - , …
:
, .
, .
a0
,
a1
,
a2
— .
, , , , , , .
, .
:
, , :
println (" : "+ objWinVista.name); //Windows Vista<br>println (" : "+ objWinVista.codename); //Longhorn<br>println (" : "+ objWinVista.bugsCount); //1 000 000 000 :-)<br>println (" :");<br>for (long numBugNumber = 0; numBugNumber < objWinVista.bugsCount; numBugNumber++)<br> {<br> println (objWinVista.bugs [numBugNumber]);<br> }
name
,codename
bugsCount
, .
bugs [i]
, , .
. , , .. . ,
a0
,
a1
,
a2
.
:
Java 2D:
GradientPaint gp = new GradientPaint (50.0f, 50.0f, Color.blue, 50.0f, 250.0f, Color.green);
RotationInterpolator rotator = new RotationInterpolator (<br> new Alpha (-1, Alpha.DECREASING_ENABLE, 0, 0, 8000, 0, 0, 0, 0, 0),<br> xformGroup, axis, 0.0f, (float)Math.PI*2.0f);
:-1, Alpha.DECREASING_ENABLE, 0, 0, 8000, 0, 0, 0, 0, 0
?
, .
, ( 3), .
:
Math.pow (2, 5)
25. , , 52 :-)
, , .
:
, :Math.summ (3, 7, 18, -2, 11, 2.3)
. |
(perl):
.
$strResult = translate text => "Hello, world!", from => $lngEnglish, to => $lngRussian, vocabulary => $vcblrGeneral, quality => 10;
?
( C Pascal) .
, , ; , ; , .
:
//rectangle1 – Rectangle rectangle1; // rectangle1.x = 80; //x rectangle1.y = 25; //y rectangle1.width = 50; // rectangle1.height = 75; // rectangle1.rotation = 30; // rectangle1.borderWeight = 2; // rectangle1.borderColor = "red"; // rectangle1.backgroundColor = "blue"; // rectangle1.alpha = 20; // // , drawRectangle (rectangle1);
,