Can we write a Container Independent code at all?

Recently, I have been reading about the Effective STL by Scott Meyers and must read book if we want to write a good re-usable code still following best practices. This article reviews Item-2 chapter of the effective STL book.

Pre-requisite: Basic understanding of STL, Type definitions, Classes in C++

Track: Advanced C++, Design principles.

Idea of Generalization:

We know the whole concept of object oriented programming is to write a piece of code which encapsulates all low level features under the hood. For instance, simple functions can be generalized as algorithms and Arrays can be generalized into containers and so on. However, can we write a code to generalize container and hide them implicitly.

Short answer: For the former it’s difficult(useless) but for the later it is possible.

Code to Generalize container: 

Just highlighting the differences between the sequence and associative container draws the below table:

Sequence Container (vector, deque, list) Associative Container (map, set)
•Push_front, push_back •No support
•No support •Time complexity: logarthimic for using

lower_bound,upper_bound

 

 

The above table clearly draws the line between the sequence and associative containers…

So, How about we then Generalize within only Sequence containers?

Answer is Nope!

Because,  lot vary between within sequence containers.

Such as List supports only Bi-directional iterators leaving out all usage of algorithms using Random access iterators.

So, finally can we wrap up and restrict only for the Associative containers- Sorry, still no!

Since, a rational to generalize sets and maps is nearly impossible as one uses single object and other uses the multiple object.

Solution:

So, it is very clear that our wish to generalize the container is impossible. But, how can we still write good software hiding or generalizing a container apart from the code.

Answer is use Encapsulation, encapsulation, encapsulation and encapsulation!(Ok that’s too much of emphasis)

Example:

Let us say we have class:

Class Widget{…}

Vector<Widget> vw;

Widget bestWidget;

Vector<Widget>::iterator i=

find(vw.begin(), vw.begin()!=vw.end(),bestWidget)

Can we now re-write:

Class Widget{…}

typedef Vector<Widget> WidgetContainer; 

WidgetContainer wc;

Widget bestWidget;

WidgetContainer::iterator i=

find(wc.begin(), wc.begin()!=wc.end(),bestWidget)

Ok, wait.. we all know how to encapsulate and hide things !

Still, what’s the point….?

Use typedef (encapsulation) to enable write us container independent re-usable and maintainable code. Period!

Now, lets us say we have a:

Class CustomerList

{

public:

…..

private:

 typedef list<Customer> CustomerContainer;

 typedef CustomerContainer::iterator Cciterator;

};

In the above code, the class hides all the internal implementation of the container hidden within itself yet the class straight forwardly is a list.

[Roll on.. Many years.. say 2025-hope c++ survives]

We realize that we no longer need to support the insert a customer at the middle. But, a new requirement to find the top 20% of the customers present comes in.

So, how do we then handle this new requirement still or without depreciating old functionality. We use n_th element algorithm but we need to change the container to vector or deque.  Hence, this gives us the freedom to not bother about implementation of the container inside our code.

Conclusion:

Yay, we did a good job! we had encapsulated a container which can be  changed based on the requirements still its is done implicitly. So, to conclude to write complete container independent code is nearly impossible.

However, we could hide and do good job of encapsulating the implementation of container from the code and maintain them for future use.

 


			

Useful transitive words to write effectively

A list of transitive actions words to write effectively:

(Source: scrapped over internet-especially from academic websites)

To indicate more information

  • Besides – Making an additional point; anyway
  • Furthermore
  • In addition
  • Moreover
  • Likewise
  • Indeed – In truth
  • In fact
  • Also
  • As well
  • Foremost – Ranking above all others; Preceding all others in spatial position
  • First, Second, Third, Finally
  • Firstly, Secondly, Thirdly

To indicate an example

  • For example
  • For instance
  • In particular
  • Particularly – Specifically or especially distinguished from others
  • Specifically
  • To illustrate
  • To demonstrate

To indicate a cause or reason

  • Since
  • Because
  • Because of
  • Due to
  • For
  • For the reason that
  • As
  • Inasmuch as – Since
  • Whereby – As a result of which, By which, “the means whereby we achieved our goal”

To indicate a result or an effect

  • Accordingly – because of the reason given
  • Consequently
  • Hence
  • So
  • Therefore
  • Thus
  • Thusly – In the way indicated
  • Thence – From that fact or reason or as a result
  • Therefrom – From that circumstance or source
  • Thereof – Of or concerning this or that, From that circumstance or source
  • Corollary – A practical consequence that follows naturally, “blind jealousy is a frequent corollary of passionate love”

To conclude

  • For the aforementioned reasons
  • For the aforementioned reasons, there is no doubt that
  • To sum up the foregoing,
  • Given these facts
  • In conclusion
  • In closing
  • To conclude

To express an opinion

  • In all due fairness
  • With good judgment, (one/we may)

To describe or make

  • vivid
  • portray
  • depict
  • exhibit
  • illustrate
  • expose
  • present
  • paint a portrait
  • limn – Trace the shape of, make a portrait of
  • delineate
  • represent
  • demonstrate
  • constitute – Form or compose
  • embodied – (adj) Expressed by
  • embody – (v) Represent or express in tangible form
  • embodiment

To prove

  • manifest – Provide evidence for; stand as proof of
  • attest – Provide evidence for
  • testify – Provide evidence for
  • certify – Provide evidence for
  • endorse, indorse – Give support or one’s approval to
  • shew – Establish the validity of something, as by an example, explanation or experiment
  • establish
  • instance – (v) Clarify by giving an example of
  • exemplify – (v) Clarify by giving an example of

To compare or contrast

  • Whereas
  • In comparison
  • In contrast
  • However
  • Although
  • On the other hand
  • Likewise
  • Similarly
  • But
  • Yet
  • Withal – Despite anything to the contrary (usually following a concession)
  • Withal – Together with this
  • Nevertheless – Despite anything to the contrary
  • Nonetheless – Despite anything to the contrary
  • Notwithstanding – Despite anything to the contrary
  • Even so – Despite anything to the contrary
  • All the same – Despite anything to the contrary

To indicate time

  • After
  • Before
  • Currently
  • During
  • Eventually
  • Finally
  • First, Second, etc.
  • Formerly
  • Immediately
  • Initially
  • Lastly
  • Later
  • Meanwhile
  • Next
  • Once
  • Previously
  • Simultaneously
  • Soon
  • Subsequently
  • Subsequent – Following in time and order
  • Hitherto, Heretofore – Used in negative statement to describe a situation that has existed up to this point or up to the present time, “The sun hasn’t rose hitherto.”
  • In due time
  • Henceforth

To indicate certainty

  • Truly
  • Sincerely
  • Genuinely
  • Surely
  • Rightfully
  • Absolutely
  • Indubitably
  • Certainly
  • Without doubt
  • Needless to say

To indicate doubt

  • Most likely
  • More likely
  • Possibly
  • Probably
  • Dubitable – Open to doubt or suspicion
  • Dubious – Distressed with uncertainty or doubt

To summarize

  • Overall
  • To summarize
  • In summary
  • To sum up
  • Paraphrased
  • Briefly
  • In brief
  • Summing up
  • To put it briefly
  • précis – A sketchy summary, Make a summary (of)
  • synopsis – A sketchy summary
  • apercu – A short synopsis

To provide a condition

  • provision, proviso – A stipulated condition
  • stipulate – Specify as a condition or requirement in a contract
  • given
  • if
  • whether
  • whenever
  • when
  • while

To express positive words

  • magnificent
  • grandeur – The quality of being magnificent or splendid or grand, the quality of being exalted in character or ideals or conduct
  • magnanimous – The quality of being exalted in character or ideals or conduct
  • fantastic
  • fantastical
  • phenomenal
  • wonderful
  • extraordinary
  • marvelous
  • superb
  • good
  • fine
  • great
  • avid – Emotionally desirable
  • avid ambition to succeed
  • excellent
  • spectacular
  • prodigious
  • grand
  • brilliant
  • glorious – Bringing great happiness and thankfulness
  • illustrious – Widely known and esteemed
  • notable – Worthy of notice
  • respected
  • impressive
  • splendid
  • splendiferous – Having great beauty and splendor
  • resplendent – Having great beauty and splendor, Richly and brilliantly colorful
  • flamboyant – Elaborately or excessively ornamented, Richly and brilliantly colorful
  • redoubtable – Having or worthy of pride
  • formidable – Extremely impressive in strength or excellence
  • prowess
  • superior
  • terrific
  • tremendous
  • wondrous – Extraordinarily good
  • wonderful
  • sublime – Inspiring awe, Lifted up or set high
  • flair – natural talent
  • knack – A special way of doing something
  • outshine – Attract more attention and praise than others
  • paramount – Having superior power and influence
  • predominant
  • preponderating
  • prevailing

To show intelligence

  • profound
  • shrewd – hardheaded (practical experience and observation) intelligence
  • astute
  • acumen – Shrewdness shown by keen insight
  • insightful
  • savvy – The cognitive condition of someone who understands
  • cognition – The psychological result of perception, learning and reasoning
  • genius
  • smart
  • sharp
  • keen
  • mastermind
  • Einstein – Someone who has exceptional intellectual ability and originality
  • work of art
  • fine art
  • maven – Someone who is dazzlingly skilled in any field
  • mavin – Someone who is dazzlingly skilled in any field
  • adept – Someone who is dazzlingly skilled in any field
  • whiz – Someone who is dazzlingly skilled in any field
  • wizard – Someone who is dazzlingly skilled in any field

To intensify

  • incredibly
  • exceedingly
  • toppingly – extremely well
  • extremely
  • extraordinarily
  • truly
  • really
  • very
  • utterly – Completely and without qualification; used informally as intensifiers, With sublimity; in a sublime manner
  • absolutely
  • perfectly
  • sublimely
  • dramatically
  • sheer – (adj.) Complete and without restriction or qualification; sometimes used informally as an intensifier; (adv.) Directly “he fell sheer into the water”

Said

  • enounced, enunciated – Speak, pronounce, or utter in a certain way
  • pronounced – Speak, pronounce, or utter in a certain way
  • articulated – Express or state clearly
  • vocalized – Express or state clearly
  • posited – Put firmly
  • stated
  • expressed
  • reported
  • alleged – Declared but not proved
  • averred – Report or maintain, To declare or affirm in a grave manner and formally as true
  • affirmed, asserted
  • wrote
  • composed
  • indited – Produce a literary work
  • penned – Produce a literary work
  • spelt – Indicate or signify
  • voiced, sounded – Give voice to
  • demean – Reduce in worth or character, usually verbally

Noted (said)

  • remarked
  • denoted – Be a sign or indication of, “Her smile denoted that she agreed”
  • observed
  • commented
  • mentioned
  • referred
  • announced
  • noticed

Precisely

  • explicitly
  • accurately
  • expressly
  • exactly
  • incisively

Numerous

  • innumerable
  • many
  • various
  • several
  • diverse
  • umpteen
  • umteen
  • myriad (noun and adj.)

Praise

  • extol – (v) Praise, glorify, or honor
  • exalt
  • glorify
  • laud
  • proclaim
  • revere
  • idolize
  • worship
  • venerate

Call Forth

  • evoke – Call forth (emotions, feelings, and responses)
  • arouse – Call forth (emotions, feelings, and responses)
  • elicit – Call forth (emotions, feelings, and responses)
  • enkindle – Call forth (emotions, feelings, and responses)
  • provoke – Call forth (emotions, feelings, and responses)
  • inflame – Arouse or excite feelings and passions
  • awake – Stop sleeping
  • conjure – Evoke or call forth, with or as if by magic
  • invoke – Evoke or call forth, with or as if by magic
  • summon – Gather or bring together
  • instill – deposit gradually

 

Master Thesis Vs. Lectures-Feb 4

Well It seems quite a time, I had updated my last post on this Blog.

But now with solid grounds, I had started my M.Sc thesis in Cetecom telecommunication Lab in Germany.

I will write and share my whole experience throughout my Journey to solve the Problem of Non-linearity. How much it would improve empower Society by conducting research.

Few observations From transitioning from Lecture based to Independent based Learning:

 1) Materials need to be explored on self-study basis.

2) Reasoning skills play a major role to understand the problem and to look for the solution on the right direction.

3)Consumes time though it will be an enjoyable run.

4)Focusing on the smaller details will create a situation to handle the problem very efficiently.

On side with Academic Lectures:

A)Material will  be consolidated so less time to consume.

B) Need to think how Prof might have solved the problem.

C) “Exam prospective result is just credits but in thesis the goal makes us to push the Human race forward”…

Dresden Microelectronics Academy 2013-Inaugural

I’ve always wonder ‘Ain’t that cool to take a break for Summer school’.  Apparently, last week I got a opportunity to visit TU-Dresden(Technische Universitat), Germany. Microelectronics was always a fascinating thing which no one could less estimate because ‘Every chip counts for the computation we do with our computer’. The every nm(nanometre) of it’s size measures the capability of computation. As, We know breaking Moore’s law will be the next big thing in the silicon sector I just wanted ‘How industry experts try to solve Manufacturing and Moore’s law problem’.

Aside:though the event was held last week I din’t find time, So my write-up won’t be chronological & it is non-linear narrative !

Tada…. Now I am here in TU-Dresden!!

Day-1 (Inaugural and Meet up)

Impressions from the first Inaugural speech by Prof. Johann Bartha(TU-Dresden)

Image

the cloud nine moment was when professor introduced different people form various University … Gladly I was the Only one from Saarland University.

Day went well with loads of talk and finally the awe moment ,, Yep,  the Music & sight seeing of City-Dresden.

Few clicks ….

Image

Footnote on Hard working von Quora!

The best advice I’ve ever heard to a question like this was something like “No problem, don’t motivate yourself, stay a loser” (in Russian, not sure how good the translation is).

Asking advise from other people doesn’t work.

 

Browsing Internet and Quora doesn’t work. You just sit down and study for 12 hours per day. Or you don’t.  

This might sound harsh, but that’s pretty much what I started to do when I was in 8th grade, what I kept doing for the next ten years and more-or-less what I keep doing nowadays. And you know, I love it when people say “It’s easy for you, you’re so smart”. It isn’t easy, nowhere near that, but it’s worth the effort.

German ‘Punctuality’ -A view

Leaving other Stereotypes. Germans have the great culture of Discipline being‘PUNCTUAL’ it’s a timely gift possessed by the entire nation .

Few occasions to cite:

1. Business meetings- They would like to start the meetings on time irrespective of people. They don’t start early nor late but They start ‘On-time’.

2. It holds true for Family gathering apart , the Transit in Germany will  be consistent and on time 

                 [Image :Train to arrive the Bahnhof(station) on-time]

The Local ‘DB'(Deutsche Bahn) arrives on time . Despite it’s timing native Germans say they are inconsistent but compared to US standards they are quiet consistent.

Though,there exists many characters to define a German quality but personally ‘Punctuality’ defines there discipline , nature of work. work life balance etc..,

 ‘Time management’- Would be the take home lesson for everyone from Deutschland!