Maybe ChatGPT can optimise MacroDroid

Jacob L

Moderator (Lawsonator)
I am doing Object Oriented Programming as a module on my Masters at university and our lecturer has incorporated AI into the module, ChatGPT specifically. AI can rewrite code in a more efficient way. It helped at least in my C# in Visual Studio. I know MacroDroid is not written in C# but it works for other languages. See this example:

My original inefficient code:

static void Main(string[] args)
{
string mode;
string exchangeRateInput;
string currencyInput;
int modeUserInput = 1;
double poundsUserInput;
double exchangeRate; // £1 is equal to $exchangerate, this is user configurable
double result;

Console.WriteLine("Please choose the mode");
Console.WriteLine("Press 1 to convert £ to $ or press 2 for $ to £");
mode = Console.ReadLine();
modeUserInput = int.Parse(mode);

Console.WriteLine("You chose mode {0}", mode);

Console.WriteLine("Please enter the exchange rate");
exchangeRateInput = Console.ReadLine();
exchangeRate = double.Parse(exchangeRateInput);

// Check the mode and perform actions based on selection
if (modeUserInput == 1)
{


Console.WriteLine("\nPlease enter the amount in £ that you want to convert to $");
currencyInput = Console.ReadLine();
poundsUserInput = double.Parse(currencyInput);
result = poundsUserInput / exchangeRate;
Console.WriteLine("\nYou want to convert {0} £s to $ using the echange rate of {1} which is: ${2}", poundsUserInput, exchangeRate, result);

}
else
{
Console.WriteLine("\nPlease enter the amount in $ that you want to convert to £");
currencyInput = Console.ReadLine();
poundsUserInput = double.Parse(currencyInput);
result = poundsUserInput * exchangeRate;
Console.WriteLine("\nYou want to convert {0} $s to £ using the echange rate of {1} which is: £{2}", poundsUserInput, exchangeRate, result);

}

Console.ReadLine(); // Holds the program open
}

ChatGPT's more efficient code:

using System;

class Program
{
static void Main(string[] args)
{
string mode;
string exchangeRateInput;
string currencyInput;
double exchangeRate;
double result;

Console.WriteLine("Please choose the mode:");
Console.WriteLine("Press 1 to convert £ to $ or press 2 for $ to £");
mode = Console.ReadLine();

Console.WriteLine($"You chose mode {mode}");

Console.WriteLine("Please enter the exchange rate:");
exchangeRateInput = Console.ReadLine();
exchangeRate = double.Parse(exchangeRateInput);

if (mode == "1")
{
Console.WriteLine("\nPlease enter the amount in £ that you want to convert to $:");
}
else if (mode == "2")
{
Console.WriteLine("\nPlease enter the amount in $ that you want to convert to £:");
}
else
{
Console.WriteLine("Invalid mode selection. Please choose 1 or 2.");
Console.ReadLine();
return;
}

currencyInput = Console.ReadLine();
double amount = double.Parse(currencyInput);

result = (mode == "1") ? amount / exchangeRate : amount * exchangeRate;

string fromCurrency = (mode == "1") ? "£" : "$";
string toCurrency = (mode == "1") ? "$" : "£";

Console.WriteLine($"\nYou want to convert {amount} {fromCurrency} to {toCurrency} using the exchange rate of {exchangeRate}. Result: {toCurrency}{result:F2}");
Console.ReadLine(); // Holds the program open
}
 

arshit09

New member
True. But it really depends on the context. It can optimize/improve the code very effectively if the code is not using other tons of files and functionalities. I think in MacroDroid's case, the code is far more complicated than ChatGPT can optimize but the developer surely can (or maybe they are already using it) use it to optimize utils or specific functions. Besides that, in the case of the ChatGPT, it comes down to two things > 1. Spend time developing the code or 2. Use ChatGPT to create the functionality code and spend time debugging it.
 

Eduardo25

New member
Igual ocurre con otros lenguajes como Python.

Si embargo, probó a optimizar algunos procesos de macrodroid con ChatGPT y los resultados no fueron los esperados.

Puede ser una cuestión de usar pronts adecuados, sin embargo intuyo que los problemas pueden ser otros.

Sea como fuere, sería Interesante conocer otras herramientas como repositorios macrodroid, además de los compilados en este foro.
 

Dm114

Well-known member
Igual ocurre con otros lenguajes como Python.

Si embargo, probó a optimizar algunos procesos de macrodroid con ChatGPT y los resultados no fueron los esperados.

Puede ser una cuestión de usar pronts adecuados, sin embargo intuyo que los problemas pueden ser otros.

Sea como fuere, sería Interesante conocer otras herramientas como repositorios macrodroid, además de los compilados en este foro.
Please write in English.
 

MacroDroidDev

Administrator
Staff member
I use GitHub co-pilot in Android Studio which can speed some development up and good for boiler plate stuff. I also use ChatGPT occasionally where appropriate but it can sometimes produce totally non working stuff.

I get quite a few support messages telling me of new features that can be implemented because ChatGPT was able to write the code for that feature. Most of these turn out to be complete rubbish.
 

Winny57

Member
Good morning,



personally chatgpt helped me completely write my website but also helps me write scripts created an application etc... But even with that you need to have certain knowledge because chatgpt is good for automating tasks and a bit of code control but sometimes it really shit is less cool lol.

This nonetheless remains a formidable development and is encouraging for the future. Everything remains to be seen because evolution is good but what we do with it is different.

For example, we can integrate an AI on its site with personalized learning which could help with the creation of macros (too bad that part of the MacroDroid code is not available, this would perhaps encourage the community to try the dev of plugin or others)

In any case, thanks again to the creator, admin and dev for this great application, known and recognized around the world for its usefulness 💪👏👏
 

mapriex

Active member
general about AIs: if you get a result in any form, you need to be able to control this, if your skill is too low, you only can do "simple" AI things.
atleast someone wrote it like this:
you need to be able to debug it.
 
Top