Örvitinn

Fastayršing gagna naušsynleg forsenda klasa

Rakst į1 žetta vištal viš Bjarne Stroustrup höfund C++ forritunarmįlsins. Mjög fróšlegt vištal ef fólk hefur įhuga C++ eša öšrum forritunarmįlum.

Žaš sem mér finnst įhugaveršast ķ vištalinu er žegar Stroustrup gagnrżnir menn fyrir aš ofnota klasa. Žetta hittir alveg ķ mark hjį honum. Hann segir aš mašur eigi ekki aš gera klasa nema mašur geti skrifaš fastayršingu gagna (svo mašur nota oršalag Snorra Agnarssonar).

Bjarne Stroustrup: What is it that makes the object a valid object? An invariant allows you to say when the object's representation when it's good and when it isn't. Take a vector as a very simple example. A vector knows that it has n elements. It has a pointer to n elements. The invariant is exactly that: the pointer points to something, and that something can hold n elements. If it holds n+1 or n-1 elements, that's a bug. If that pointer is zero, it's a bug, because it doesn't point to anything. That means it's a violation of an invariant. So you have to be able to state which objects make sense. Which are good and which are bad. And you can write the interfaces so that they maintain that invariant. That's one way of keeping track that your member functions are reasonable. It's also a way of keeping track of which operations need to be member functions. Operations that don't need to mess with the representation are better done outside the class. So that you get a clean, small interface that you can understand and maintain.

Aš sjįlfsögšu eru til żmsar skošanir į žessum mįlum. Bertrand Meyer höfundur Eiffel forritunarmįlsins er t.d. ekki sammįla Stroutrup varšandi member föll. Hann sér ekkert athugavert viš aš hafa tugi member falla ef žaš hentar og rökstyšur žaš įgętlega ķ frįbęrri bók sinni, Object Oriented Software Construction. Stroustrup vill aftur į móti fęra allar ašgeršir śt śr klasanum ef žęr žurfa ekki aš vera žar.

Mér finnst C++ skemmtilegt forritunarmįl. Ef mašur hefur ašgang aš góšum klasasöfnum (librarķum) er ķ raun afskaplega žęgilegt aš forrita meš C++. En vandamįliš er aš mašur er stundum gjarn į aš fara śt ķ of flókna forritun įn gildrar įstęšu. Stundum žegar menn agnśast śt ķ C++ og benda į ašra valkosti held ég aš munurinn sé fyrst og fremst ašgangur aš klasasöfnum. Helsti kostur Java og Python (vafalķtiš Perl lķka) er aš librarķin sem koma meš standard dreifingunum eru grķšarlega öflug. Mašur žarf aš leita betur til aš finna sambęrilega hluti fyrir C++ en žeir eru til.
Meš forritunarašferšum eins og roii getur mašur oft skrifaš mun snyrtilegri kóša meš C++ en mörgum öšrum forritunarmįlum.

Ég bķš spenntur eftir öšrum hluta vištalsins.

1: Sį vķsun ķ žessum umręšužręši į Joel On Software.

forritun