My New Friend
-
Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of
switch case:
statements utilizing numeric constants which should be in numeric order so the random numbercase
argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in theswitch
statement are reorganized to match it is then necessary to renumber in sequence the lengthy list ofcase
statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond Tutu -
Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of
switch case:
statements utilizing numeric constants which should be in numeric order so the random numbercase
argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in theswitch
statement are reorganized to match it is then necessary to renumber in sequence the lengthy list ofcase
statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond TutuHuh ? You have performance issues on a switch that you need to re-order the case statements ?
CI/CD = Continuous Impediment/Continuous Despair
-
I swear English is my native language though I sometimes seem to speak it w/ a slight Polish accent. Maybe that's the cause of the confusion.
-
Huh ? You have performance issues on a switch that you need to re-order the case statements ?
CI/CD = Continuous Impediment/Continuous Despair
The performance issue was re/ my fingers re-editing the lengthy list of case statements. Fortunately awk will from now on do it for me.
-
Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of
switch case:
statements utilizing numeric constants which should be in numeric order so the random numbercase
argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in theswitch
statement are reorganized to match it is then necessary to renumber in sequence the lengthy list ofcase
statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond TutuWhy are you reordering the switch, exactly? Performance issues? If so, you might get a lot more mileage out of using compiler specific extensions to implement a pure jump table out of it.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Why are you reordering the switch, exactly? Performance issues? If so, you might get a lot more mileage out of using compiler specific extensions to implement a pure jump table out of it.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
Maybe relying on fall through?
-
Maybe relying on fall through?
Yikes. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Are you perplexed because he could’ve used Polymorphism via Interfaces and solved this problem?
interface IDataSaver(){
int Save();
}class InternetSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. Http write dataToSave to URL;
//. 2. Return 0 - success
}
}class FileSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. File write dataToSave to FILE;
//. 2. Return 0 - success
}
}class DBSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. write dataToSave to DATABASE;
//. 2. Return 0 - success
}
}// driver
List allDataSavers = new List();
allDataSavers.Add(new InternetSaver());
allDataSavers.Add(new FileSaver());
allDataSavers.Add(new DBSaver());foreach (IDataSaver ds in allDataSavers){
ds.Save(); /// no need to determine type (no switch) bec all implement Save()
} -
Yikes. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Are you perplexed because he could’ve used Polymorphism via Interfaces and solved this problem?
interface IDataSaver(){
int Save();
}class InternetSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. Http write dataToSave to URL;
//. 2. Return 0 - success
}
}class FileSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. File write dataToSave to FILE;
//. 2. Return 0 - success
}
}class DBSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. write dataToSave to DATABASE;
//. 2. Return 0 - success
}
}// driver
List allDataSavers = new List();
allDataSavers.Add(new InternetSaver());
allDataSavers.Add(new FileSaver());
allDataSavers.Add(new DBSaver());foreach (IDataSaver ds in allDataSavers){
ds.Save(); /// no need to determine type (no switch) bec all implement Save()
} -
CPallini wrote:
Imagine the class diagram
You mean in the original situation where he is creating separate classes for each of his
switch
statements, right? Yeah, it would get crazy big! -
Are you perplexed because he could’ve used Polymorphism via Interfaces and solved this problem?
interface IDataSaver(){
int Save();
}class InternetSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. Http write dataToSave to URL;
//. 2. Return 0 - success
}
}class FileSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. File write dataToSave to FILE;
//. 2. Return 0 - success
}
}class DBSaver : IDataSaver{
String dataToSave;
Int Save(){
// 1. write dataToSave to DATABASE;
//. 2. Return 0 - success
}
}// driver
List allDataSavers = new List();
allDataSavers.Add(new InternetSaver());
allDataSavers.Add(new FileSaver());
allDataSavers.Add(new DBSaver());foreach (IDataSaver ds in allDataSavers){
ds.Save(); /// no need to determine type (no switch) bec all implement Save()
}Perhaps I should provide the code. I prefer them in the same order as declared in the class not shown as it is a class cTest global variable.
void Random\_\_METHOD() { static const int last\_case = 96; // Random Number Generator auto \_case\_ = m\_cSCALAR\_RNG.operator() < int > (0, last\_case); switch(\_case\_) { default: throw einternal\_error\_eXception; case 0: Random\_\_default\_constructor(); break; case 1: Random\_\_primordialTimePoint(); break; case 2: Random\_\_DIAGNOSTIC\_SNAPSHOT\_HASH(); break; case 3: Random\_\_recordTermination\_time\_point\_node\_spec(); case 4: Random\_\_open\_with\_arguments(); break; case 5: Random\_\_open(); break; case 6: Random\_\_close(); break; case 7: Random\_\_is\_open(); break; case 8: Random\_\_set\_toNascentState(); break; case 10: Random\_\_swap(); break; case 11: Random\_\_startTransaction(); break; case 12: Random\_\_endTransaction(); break; case 13: Random\_\_cancelTransaction(); break; case 14: Random\_\_is\_activeTransaction(); break; case 15: Random\_\_activeTransaction\_ctransaction\_datum(); break; case 16: Random\_\_is\_saved(); break; case 17: Random\_\_save(); break; case 18: Random\_\_offset(); break; case 19: Random\_\_size(); break; case 20: Random\_\_eofOffset(); break; case 21: Random\_\_mirror(); break; case 22: Random\_\_archivesPaths(); break; case 23: Random\_\_archivesFilenames(); break; case 24: Random\_\_fullPath(); break; case 25: Random\_\_fileName(); break; case 26: if(m\_rfe) {} break; case 27: if(!m\_rfe) {} break; case 28: m\_rfe == m\_rfe; break; case 29: m\_rfe != m\_rfe; break; case 30: Random\_\_read(); break; case 31: Random\_\_output(); break; case 32: Random\_\_delete(); break; case 33: Random\_\_setOffset(); break; case 34: Random\_\_incOffset(); break; case 35: Random\_\_decOffset(); break; case 36: Random\_\_adjust\_eofOffset(); break; case 37: Random\_\_set\_eofOffset(); break; case 38: Random\_\_initializedIntervals(); break; case 39: Random\_\_uninitializedIntervals(); break; case 40: Random\_\_treeEmpty(); break; case 41: Random\_\_treeSize(); break; case 42: Random\_\_number\_ofUndosAvailable(); break; case 43: Random\_\_undo(); break; case 44: Random\_\_redo(); break; case 45: Random\_\_number\_ofRedoBranches(); break; case 46: Random\_\_undo\_node\_spec\_time\_point(); break; case 47: Random\_\_undo\_node\_spec\_ctransaction\_datum(); break; case 48: Random\_\_undo\_node\_spec\_time\_point\_vector\_cedit\_datum(); break; case 49: R