Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: tag definition or tagset

$
0
0

[quote user="blumax57"]I used method Select Case
I do not know why use anything else :)[/quote]

Well, it's not easy to explain it ... as anything what is treated as "best practices" in a particular industry. They are usually based on shared experience and some general concepts, discussed and proven by history. In the case of software development and development languages they moreover exist in a context of specifc language or group of languages (e.g. best practices for object oriented design cannot be directly applied to functional languages).

Switch statement (select in VBA) is usually treated as "potentially dangerous", but it does not mean it's automatically bad. It depends on context, type and size of the macro and its functionality. Unfortunately in VBA there is not a nice simple way how to replace select - case statement with something else, comparing to "more object oriented langauges" like C++ or C# where often other approach and code can be used.

So why to be careful with select - case statement? It leads to poorly maintainable code if used too often. If there is one switch in the code, I am sure it's not a problem at all. But if the same construction "if this value, do this" exists several times in the same macro, the code is probably bad: If an amount of tested values will change in future, it's necessary to go through the whole code and to hope you will find all places where the values are tested. And there is no way how to be sure you modified all code in a right way ... until the macro will fail. Sometimes it's even not necessary to use it and it is just a result of wrong macro architecture.

But there is also "a macro context": If the macro is short or will be used for a limited period of time, there is less demand to write perfect and clean code. But if it's expected the macro will be maintained and enhanced in future, it's wise to invest time and to try to investigate different approach (they exist even in VBA for some scanarios) or to minimize how many time select - case statement is used (e.g. to centralize it in one more general method, which follows DRY rule).

With regards,

  Jan


Viewing all articles
Browse latest Browse all 7260

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>