-
Path: news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!n
ews-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-
06.dc1.easynews.com.POSTED!not-for-mail
From: A.L. <l...@a...com>
Newsgroups: pl.comp.programming
Subject: Re: kwestia estetyczna
Message-ID: <r...@4...com>
References: <4...@n...onet.pl>
<4...@n...onet.pl>
X-Newsreader: Forte Agent 4.2/32.1118
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 137
X-Complaints-To: a...@e...com
Organization: Forte Inc. http://www.forteinc.com/apn/
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will
be unable to process your complaint properly.
Date: Sun, 07 Aug 2011 10:53:55 -0500
Xref: news-archive.icm.edu.pl pl.comp.programming:191731
[ ukryj nagłówki ]On Sun, 07 Aug 2011 12:02:07 +0200, m...@t...pl wrote:
>
>
>> tak naprawde jak sie zastanowic to duze zaglebienia ifow
>> nie zdarzaja sie czesto - nawet 'if w ifie' to raczej ewenement,
>
>Jesli napiszemy tak:
>if( warunek1 ) {
> if( warunek2 ) {
> if( warunek3 ) {
> if( warunek4) {
> if( warunek5 ) {
> operacje_1();
> }
> }
> operacje_2();
> }
> }
>}
>
>to zaglebienie ifow jest duze. Analiza po pierwszym spojrzeniu
>na taki kod jest utrudniona - latwo pomylic sie w liczeniu
>klamerek.
>
>
>Jesli napiszemy tak:
>if( !warunek1 ) return;
>if( !waruenk2 ) return
>// reszta kodu
>
>to od razu mamy pewnosci ze warunek1 i warunek2 nie
>ma nic wsplolnego z operacje_2(). Analiza
>wersji z return jest prostsza.
>
>
>> musze kiedys zwrocic na to wiecej uwagi
>> (mozna by moze nawet powiedzec ze same ify zdarzaja sie srednio
>> czesto - w sensie ifow nie ma wcale az tak duzo )
>Wlasnie siedze nad takim projektem w ktorym ze wzgledu na
>ogromna ilosc testow i ifow w "kazdej" klasie zostaly do
>tego celu wydzielone 3 wirtualne metody. One niemal nic
>innego nie robia tylko:
>
>tmp = dane_tymczasowe()
>if( ! jakis_test( tmp ) ) {
> jakies_logi();
> return kod_bledu;
>}
>
>
>Druga procedure na okolo 1-2tys wierszy mam taka:
>a = dane_a1()
>b = dane_b1()
>p1 = funckcja_nieliniowa( a , b )
>
>a = dane_a2()
>b = dane_b2()
>p2 = funckcja_nieliniowa( a , b )
>
>..........................
>return p1 * p2 * ... * pn;
>Przy czym ponad 50% tego kodu to komentarze.
>
>Nie da sie tego podzielic na male funkcje z wyraznymi
>korzysciami.
>
>Pozdrawiam
Cytat 1
Single Entry Point, Single Exit Point Style
A piece of code is likely to be more easily understood if it has only
one entry point (at the top of its listing) and only one exit point at
(or near, e.g., a return statement just before the closing "}" of a
non-void C++ function) the bottom of its listing. In C++, this
philosophy has the following implications:
Don't use goto statements. If the target of a goto is not at the start
of its block, then its block has two entry points; if the goto
statement is not at the end of its block, then its block has two exit
points. The goto statement can also have other undersirable effects on
the understanding of the listing; for example, see the Loop Style
section.
Don't use exit statements. Since a typical C++ program ends at a
return 0; statement at the end of its main function, the use of an
exit statement provides a second exit point from the program.
Don't use break statements except to end a case of a switch structure.
To use a break, say, to exit a loop, provides the loop with a second
exit point.
Some argue for exceptions to the rules stated above in order to
simplify the flow of control amidst complex code. For example, some
argue that if main calls on blah, which calls on ..., which calls on
gallumph, and an unusual error is detected by the code of the latter
function that makes further processing within the program pointless,
it is easier for the programmer to use an exit statement to end the
run of the program than to provide appropriate if statements, one in
each of the chain of functions alluded to above, to provide "normal"
exit from the main function's end-of-listing or return 0; statement.
Since student exercises rarely get complex enough to make a strong
argument along these lines, I prefer my students to follow the
guidelines above.
Cytat 2
Length of a Subprogram
KISS - Keep it short, smarty! (You thought I would use "stupid"?
Stupid people don't write software.)
In general, it's wise to keep every subprogram (in C++, every
function, including main) short. A reader typically tries to
understand one function at a time, so keeping functions short makes
them more "digestable." A classical guideline: a maximum of 25 lines
of code, what used to be the maximum viewable on a computer screen
using a typical text editor. Today's screens often show more than 25
lines, and I won't send a student to the guillotine for a 26th line,
but if you're in excess of 30, there's probably a natural way to
abbreviate your function, perhaps by extracting one or more blocks of
its code as (a) separate function(s).
http://purple.niagara.edu/boxer/essays/prog/style.ht
m#toc
Cytat 3:
Rule of Parsimony: Write large program only if it is demonstrated that
nothing else will do
Teh Art of UNIX Programming, strona 40
Ja mam wrazenie neijakie ze 20 lat programowania strukturalnego (1965
- 185) i prawie 30 lat obiektowego (1985 - do dzis) jakos wyparowaly.
A moze tego nie ucza dzisiaj?... I prowracamy do programowanie w
COBOLU? Programwoania w OBOLU przy pomocy Javy?...
Następne wpisy z tego wątku
- 07.08.11 16:51 A.L.
- 07.08.11 18:27 Paweł Kierski
- 07.08.11 18:35 Paweł Kierski
- 07.08.11 18:45 A.L.
- 07.08.11 19:07 Wojciech Muła
- 07.08.11 20:29 A.L.
- 07.08.11 21:22 m...@t...pl
- 07.08.11 21:35 A.L.
- 08.08.11 08:03 m...@t...pl
- 08.08.11 13:27 A.L.
- 08.08.11 14:56 Adam Przybyla
- 08.08.11 16:30 Paweł Kierski
- 08.08.11 17:40 A.L.
- 08.08.11 17:41 A.L.
- 08.08.11 19:14 Adam Przybyla
Najnowsze wątki z tej grupy
- Popr. 14. Nauka i Praca Programisty C++ w III Rzeczy (pospolitej)
- Arch. Prog. Nieuprzywilejowanych w pełnej wer. na nowej s. WWW energokod.pl
- 7. Raport Totaliztyczny: Sprawa Qt Group wer. 424
- TCL - problem z escape ostatniego \ w nawiasach {}
- Nauka i Praca Programisty C++ w III Rzeczy (pospolitej)
- testy-wyd-sort - Podsumowanie
- Tworzenie Programów Nieuprzywilejowanych Opartych Na Wtyczkach
- Do czego nadaje się QDockWidget z bibl. Qt?
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
Najnowsze wątki
- 2025-02-06 PROGRAM DOPŁAT DO AUT ELEKTRYCZNYCH TO ABSURD. ZA ŚRODKI Z KPO KUPIMY NIEMIECKIE I CHIŃSKIE AUTA
- 2025-02-05 ceny OC
- 2025-02-05 Re: ceny OC
- 2025-02-05 Re: ceny OC
- 2025-02-07 Smar do video
- 2025-02-06 Litowe baterie AA Li/FeS2 a alkaliczne
- 2025-02-07 Gliwice => Business Development Manager - Network and Network Security
- 2025-02-07 Warszawa => System Architect (Java background) <=
- 2025-02-07 Warszawa => System Architect (background deweloperski w Java) <=
- 2025-02-07 Warszawa => Solution Architect (Java background) <=
- 2025-02-07 Gliwice => Ekspert IT (obszar systemów sieciowych) <=
- 2025-02-07 Lublin => Programista Delphi <=
- 2025-02-07 Warszawa => Architekt rozwiązań (doświadczenie w obszarze Java, AWS
- 2025-02-07 Dęblin => Node.js / Fullstack Developer <=
- 2025-02-07 Bieruń => Spedytor Międzynarodowy (handel ładunkami/prowadzenie flo