Question

In the project I am working right now, we have some python and some C# code....

In the project I am working right now, we have some python and some C# code. At some point, I call from python a subprocess which starts a C# executable. This C# code returns an error code, which has to be understood on the python side and a readable report has to be created.

This means, both sides "must speak the same language". So, at the end I have to handle a mapping {error codes: readable explanation} (normally we implement this as static properties of a enumeration class). This is of course a case of code duplication, and prone to be inconsistent.

My ideas to mitigate this have been so far:

Automatically generate code: let's say when the mapping on the C# part changes, the code will be parsed and automatically generated on the the python side. While I think this is technically quite correct, I have to somehow parse C# code and translate it to valid python code, which is something probably hard to get it right at the first time.

Partial processing of error code on the python side. This means, just check for zero or non-zero return value, and if non-zero, read the stdout of the C# process and report it, no matter what. While this is very easy to implement, I see some possible caveats, like the C# process crashing in an unexpected way and reporting some exception traceback or similar.

Since this must be a quite common problem, I would like to know what are the easiest and more maintainable approaches used in the industry. Thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I would use code generation from single source.

E.g. define error codes in a text file and use T4 to generate C# enum and something similar to generate python code. Or write C# enums directly and use code generation to generate python only. You dont have to parse C# code necessarily, you can use some .net tool that dynamically loads your .net assembly and uses reflection to get enum members. Why not to use T4 to generate python enums as well? :)

I believe code generation is the best way to avoid violation of DRY principle in this case.

Add a comment
Know the answer?
Add Answer to:
In the project I am working right now, we have some python and some C# code....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help writing this C code. Here is the description: Let's say we have a...

    I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know,  for each word in the dictionary,...

  • I am practicing python by doing some projects, and I am stuck on this function. I'd...

    I am practicing python by doing some projects, and I am stuck on this function. I'd like to know how to do it without using statements like break, input, print, or continue. The first parameter represents a "person to friends" dictionary, the second parameter represents a "person to clubs" dictionary, and the third parameter represents a person's name in the same format as the dictionary keys). Using the recommendation system described below, the function should return the club recommendations for...

  • C programming is the main one and pick another code of choice!!! Background This assignment is...

    C programming is the main one and pick another code of choice!!! Background This assignment is based on one of the Big Ideas in this course, namely that reading C source code is a real aid in learning how to write C code. To that end, in this project, you write a program that scans C source from the 'Net and calculates some simple statistics. We're learning lots of concepts, and by running the program you write here on several...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • This is my code in C++, my code is working pretty good but there are some...

    This is my code in C++, my code is working pretty good but there are some stuff needs ti be changed I included theb below the my code: include<iostream> #include<string> #include<vector> #include<sstream> #include<algorithm> using namespace std; //Structure struct TokenFreq { //Structure variables string token; int freq=1; }; //Method matrixInit() void matrixInit(vector<vector<int> > &matrix, int numRows, int numCols) { //Declare the needed variables int index1, index2;    //Resize matrix.resize(numRows, vector<int>(numCols));    //Loop for(index1 = 0; index1 < numRows; index1++) { //Loop...

  • Hi everyone, For my Assignment I have to use C# in order to create a validation...

    Hi everyone, For my Assignment I have to use C# in order to create a validation form and include the following things to register and validate: Email Address, Username, Password, Retype Password, and a Submit Button. I have figured out some of the code for the Email Address validation: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Validation4 {     public partial class Form1 : Form     {        ...

  • Please help with my car traffic simulator! Code that I already have below, I do not know how to...

    Please help with my car traffic simulator! Code that I already have below, I do not know how to start it off! public class IntersectionSimulation { private final static int EAST_WEST_GREEN_TIME = 30 ; private final static int[] NORTH_SOUTH_GREEN_TIMES = { 20, 24, 30, 42 } ; private final static int[] CAR_INTERSECTION_RATES = { 3, 5, 10 } ; private final static int[] CAR_QUEUEING_RATES = { 5, 10, 30 } ; private final static int[] EXPERIMENT_DURATIONS = { 3*60, 5*60,...

  • Overview Writing in the C language, implement a very basic shell, called smash. In this project,...

    Overview Writing in the C language, implement a very basic shell, called smash. In this project, we will work on processing strings and using the appropriate system calls. Build System setup Before we can start writing code we need to get our build system all setup. This will involve writing a very simple makefile. You should leverage your Makefile project for this part of the assignment! Write a Makefile that provides the three targets listed below all - The default...

  • Project factoring need c++ code Because there are some numbers are very large, like 1316872907073608066468826571215294289 i...

    Project factoring need c++ code Because there are some numbers are very large, like 1316872907073608066468826571215294289 i really want to know how to read the file with this kind of numbers and store For this project you will be factoring numbers, significantly smaller than the numbers used for RSA of course, but they will still be fairly large numbers. So large in fact that if you are using C++ you may not be able to natively represent these numbers. If you...

  • Here is the code I have so far. I'm trying to figure out how to implement...

    Here is the code I have so far. I'm trying to figure out how to implement a boolean and use precedence. The 2nd expression should be 14 but it comes out as 28 so I'm definitely not understanding. #include <stack> #include <iostream> #include <string> using namespace std; // Function to find precedence of // operators. int precedence(char op) {    if (op == '+' || op == '-')        return 1;    if (op == '*' || op ==...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT