Just dreaming...

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 2237 Views - Last Post: 02 March 2020 - 08:06 AM

#1 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Just dreaming...

Posted 19 February 2020 - 03:15 AM

Wouldn't it be nice if c++ data/threading structure was more like the following:
void main(){

printOperation(){
port->lpt1(*attrs_variable, port_attrs)

`Thread(){
startThread();
//print operation consisting of various calls to printer attributes
stopThread();
}

};

serialOperation(){
port->com1(*attrs_variable, port_attrs)

`Thread(){
start();
//serial communication operation consisting of various calls to serial port attributes
stop();
}

};

}

etc...



Wherein the threading is transitive, taking up the next available thread, and the operations are accessible for simultaneous threading on multiple threads. This way you could call up the operations as needed like objects, rather than manipulating data as its set up currently.

With an IDE consisting of a menu interface that pulls up a complete c++ reference for the scope of the module, with an example for each language component as follows:

file operation dropdown menu
	read (ie: pulls up basic_ifstream/istringstream/etc...)
	write
	edit
    parse
    etc...
math operation dropdown menu
	add
	subtract
	multiply
	divide
    etc...
display operation dropdown menu
    vga
    hdmi
    dvi
    com
    etc...
print operation dropdown menu
	lpt1
	lpt2
    etc...
port operation dropdown menu
	com1
	com2
    etc...	
network operation dropdown menu
	netport 8080
	netport 8180
    ect...



Is This A Good Question/Topic? 0
  • +

Replies To: Just dreaming...

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7289
  • View blog
  • Posts: 24,666
  • Joined: 05-May 12

Re: Just dreaming...

Posted 19 February 2020 - 07:25 AM

View Postjv1597, on 19 February 2020 - 05:15 AM, said:

This way you could call up the operations as needed like objects, rather than manipulating data as its set up currently.


One of the core concepts of object oriented programming is message passing. This is what you are calling "call up the operations". You can already do this in C++. If you are busy "manipulating data" then you likely not following an object oriented approach.

As a side node, C++ is meant to be multi-paradigm because of the wide variety of people using it -- including people who want to just use C++ as as "C-with-classes". Since your dream is already reality, are you saying that people are not allowed to use other paradigms in C++?

View Postjv1597, on 19 February 2020 - 05:15 AM, said:

the operations are accessible for simultaneous threading on multiple threads.

This already present in C++. You can call an object's methods from any thread that you want to. It's going to be up to the implementer of that object whether they have written their code in a thread safe manner where they can support multiple cross thread calls.
Was This Post Helpful? 0
  • +
  • -

#3 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 19 February 2020 - 02:33 PM

skydiver,
Thanks for the info. I was just speaking hypothetically with regard to the simplicity, and structure. Nothing serious. The paradigm aspect is a case in point. It makes things so complicated. The data structure in use by c++ components is pretty messy imo. That's why I thought it would be nicer to have an IDE with the reference capability to aggregate the language components for the coder per module specs. This would pull up a tailored listing of components required for the scope of the module (unlike list widgets), rather than having to look them up on c++ reference sites.

As far as I can tell the operation() method would cover everything from file/string operations to network and device operations.:)
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7289
  • View blog
  • Posts: 24,666
  • Joined: 05-May 12

Re: Just dreaming...

Posted 19 February 2020 - 03:17 PM

View Postjv1597, on 19 February 2020 - 04:33 PM, said:

The data structure in use by c++ components is pretty messy imo. That's why I thought it would be nicer to have an IDE with the reference capability to aggregate the language components for the coder per module specs.

Can you elaborate on what you mean by "data structure"? I'm not sure how an IDE listing language components would help.

Can you also explain what you mean by the word "module"? It feels like you have attached a special meaning to this word that is different from the way C++ practitioners use the word "module" prior to C++20 (e.g. compilation unit), as well as different from the C++20 sense (e.g. package)

View Postjv1597, on 19 February 2020 - 04:33 PM, said:

As far as I can tell the operation() method would cover everything from file/string operations to network and device operations.:)/>

Can you explain further what you mean by this?
Was This Post Helpful? 0
  • +
  • -

#5 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 19 February 2020 - 04:32 PM

I'm speaking in the ordinary sense. Data structure -> memory-level code functionality. Module -> application module. Language component -> Types/structs/methods/funcitons/etc.. I think you c++ experts know the language so well, you wouldn't even dream of anything better. :offtopic: :rockon: :)
Was This Post Helpful? 0
  • +
  • -

#6 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 19 February 2020 - 04:46 PM

If there ever were a "operation()" method that could be called called as an object, it would pretty much do every bit you would ever need as with c++ but much more efficiently. If you think about it its got everything in one simple "struct" per se. Hypothetically, as a code element in memory, it's got built-in autonomous threading capability and prioritization. So if you apply the operation() concept to any operation you can think of for any application, whether it be working with strings, files, devices, etc... you can pretty much accomplish any task you need done with just one simple code principle, "operation()".
ie:

Rather than the following example found at CPlusPlus.com Forum:
public:
    static void Main()
    {
        String^ name;
        String^ message;
        StringComparer^ stringComparer = StringComparer::OrdinalIgnoreCase;
        Thread^ readThread = gcnew Thread(gcnew ThreadStart(PortChat::Read));

        // Create a new SerialPort object with default settings.
        _serialPort = gcnew SerialPort();

        // Allow the user to set the appropriate properties.
        _serialPort->PortName = SetPortName(_serialPort->PortName);
        _serialPort->BaudRate = SetPortBaudRate(_serialPort->BaudRate);
        _serialPort->Parity = SetPortParity(_serialPort->Parity);
        _serialPort->DataBits = SetPortDataBits(_serialPort->DataBits);
        _serialPort->StopBits = SetPortStopBits(_serialPort->StopBits);
        _serialPort->Handshake = SetPortHandshake(_serialPort->Handshake);

        // Set the read/write timeouts
        _serialPort->ReadTimeout = 500;
        _serialPort->WriteTimeout = 500;

        _serialPort->Open();
        _continue = true;
        readThread->Start();

        Console::Write("Name: ");
        name = Console::ReadLine();

        Console::WriteLine("Type QUIT to exit");

        while (_continue)
        {
            message = Console::ReadLine();

            if (stringComparer->Equals("quit", message))
            {
                _continue = false;
            }
            else
            {
                _serialPort->WriteLine(
                    String::Format("<{0}>: {1}", name, message) );
            }
        }

        readThread->Join();
        _serialPort->Close();
    }

    static void Read()
    {
        while (_continue)
        {
            try
            {
                String^ message = _serialPort->ReadLine();
                Console::WriteLine(message);
            }
            catch (TimeoutException ^) { }
        }
    }

    static String^ SetPortName(String^ defaultPortName)
    {
        String^ portName;

        Console::WriteLine("Available Ports:");
        for each (String^ s in SerialPort::GetPortNames())
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("COM port({0}): ", defaultPortName);
        portName = Console::ReadLine();

        if (portName == "")
        {
            portName = defaultPortName;
        }
        return portName;
    }

    static Int32 SetPortBaudRate(Int32 defaultPortBaudRate)
    {
        String^ baudRate;

        Console::Write("Baud Rate({0}): ", defaultPortBaudRate);
        baudRate = Console::ReadLine();

        if (baudRate == "")
        {
            baudRate = defaultPortBaudRate.ToString();
        }

        return Int32::Parse(baudRate);
    }

    static Parity SetPortParity(Parity defaultPortParity)
    {
        String^ parity;

        Console::WriteLine("Available Parity options:");
        for each (String^ s in Enum::GetNames(Parity::typeid))
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("Parity({0}):", defaultPortParity.ToString());
        parity = Console::ReadLine();

        if (parity == "")
        {
            parity = defaultPortParity.ToString();
        }

        return (Parity)Enum::Parse(Parity::typeid, parity);
    }

    static Int32 SetPortDataBits(Int32 defaultPortDataBits)
    {
        String^ dataBits;

        Console::Write("Data Bits({0}): ", defaultPortDataBits);
        dataBits = Console::ReadLine();

        if (dataBits == "")
        {
            dataBits = defaultPortDataBits.ToString();
        }

        return Int32::Parse(dataBits);
    }

    static StopBits SetPortStopBits(StopBits defaultPortStopBits)
    {
        String^ stopBits;

        Console::WriteLine("Available Stop Bits options:");
        for each (String^ s in Enum::GetNames(StopBits::typeid))
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("Stop Bits({0}):", defaultPortStopBits.ToString());
        stopBits = Console::ReadLine();

        if (stopBits == "")
        {
            stopBits = defaultPortStopBits.ToString();
        }

        return (StopBits)Enum::Parse(StopBits::typeid, stopBits);
    }

    static Handshake SetPortHandshake(Handshake defaultPortHandshake)
    {
        String^ handshake;

        Console::WriteLine("Available Handshake options:");
        for each (String^ s in Enum::GetNames(Handshake::typeid))
        {
            Console::WriteLine("   {0}", s);
        }

        Console::Write("Handshake({0}):", defaultPortHandshake.ToString());
        handshake = Console::ReadLine();

        if (handshake == "")
        {
            handshake = defaultPortHandshake.ToString();
        }

        return (Handshake)Enum::Parse(Handshake::typeid, handshake);
    }
};"



You would do:

comportOperation(){
port->com1(*attrs_variable, port_attrs)

`Thread: //thread instantiated if operation() app module requires special processing priority

startThread();

   synchOperation(attrs_variable, synch_buf);
   readOperation(dev/C:\shared\etc, *read_buf);
   displayOperation(read_buf, cout);

stopThread();

}



Sounds pretty good to me... :bananaman:/>/>/>/>/>

This post has been edited by Skydiver: 19 February 2020 - 08:10 PM
Reason for edit:: Put additional code in code tags.

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7289
  • View blog
  • Posts: 24,666
  • Joined: 05-May 12

Re: Just dreaming...

Posted 19 February 2020 - 08:24 PM

Unfortunately, the code you presented above in post #6 is non-standard C++. It's C++/CLI which is a Microsoft spin on C++ to let it integrate with the managed .NET Framework. Furthermore, the complexity you are seeing there is due to the nature of how the .NET Framework's SerialPort class was designed. It's not the fault of the C++ languague.

Notice that lines 12-22 and 65-176 are just there to support querying the user and setting up the serial port settings. Its the same settings that you somehow just have as your magical port_attrs. How many lines of setup would your new C++ variant need to query the user and setup the same settings?

You also have your magic syncOperation(), readOperaiton(), and displayOperation(). What would those look like when expanded out?
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7289
  • View blog
  • Posts: 24,666
  • Joined: 05-May 12

Re: Just dreaming...

Posted 19 February 2020 - 08:38 PM

View Postjv1597, on 19 February 2020 - 06:32 PM, said:

I'm speaking in the ordinary sense. Data structure -> memory-level code functionality.

Can you provide specific examples?

All the modern bits of C++ make a point of following object oriented principles and make it so that you don't need to know how a class is implemented -- you don't need to know what bytes go where. The standard just guarantees that certain objects will behave a particular way and have some performance characteristics.

It's true, though, that due to C++'s C legacy, there are some things that still require a programmer to have a general layout of objects in memory, but this is due attempting to continue supporting pointer arithmetic and just moving pointers around on objects that the C++ standard says will be store contiguously in memory. In my experience, these are only used primarily for backward compatibility with C which needs things laid out that way. In general, though, modern C++ discourages you from having raw pointers to objects to iterate over them. It instead has you use std::iterator to go through objects so that you don't need to know how the memory is laid out.
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7289
  • View blog
  • Posts: 24,666
  • Joined: 05-May 12

Re: Just dreaming...

Posted 19 February 2020 - 08:49 PM

View Postjv1597, on 19 February 2020 - 06:32 PM, said:

I'm speaking in the ordinary sense. ... Module -> application module. Language component -> Types/structs/methods/funcitons/etc..

Okay. So given that you said this earlier in the thread:

View Postjv1597, on 19 February 2020 - 05:15 AM, said:

With an IDE consisting of a menu interface that pulls up a complete c++ reference for the scope of the module, with an example for each language component as follows:

to me it now looks like a chicken-and-egg problem.

How can the IDE figure out what components to list for the programmer until the programmer starts writing some code? Read the programmer's mind? The programmer will have to write some code that has some components. Based on whatever components the IDE finds in the code, it'll present those same components to the programmer. Or is the IDE supposed to guess based on the current components seen so far, it'll do a LinkedIn or Facebook type graph search of what other components you may likely want to also use? Is the IDE also supposed to also grovel through github, bitbucket, and StackOverflow looking for other components that maybe useful?
Was This Post Helpful? 0
  • +
  • -

#10 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 20 February 2020 - 08:15 AM

Quote

How can the IDE figure out what components to list for the programmer until the programmer starts writing some code?


I figured the IDE interface would consist of a set of drop-down menus to help narrow the reference search. Kinda like an API. The references would basically be the set of language components your module requires based on the operation you choose as mentioned in the above post:
string operation dropdown menu
    read
    write
    edit
    compare
    parse
    etc...
array operation dropdown menu
    read
    write
    edit
    compare
    parse
    etc...
file operation dropdown menu    
    read (ie: pulls up basic_ifstream/istringstream/etc...)
    write
    edit
    parse
    etc...
math operation dropdown menu
    add
    subtract
    multiply
    divide
    etc...
display operation dropdown menu
    vga
    svga
    hdmi
    dvi
    com
    etc...
print operation dropdown menu
    lpt1
    lpt2
    etc...
port operation dropdown menu
    com1
    com2
    etc... 
network operation dropdown menu
    netport 8080
    netport 8180
    ect...




Quote

You also have your magic syncOperation(), readOperaiton(), and displayOperation(). What would those look like when expanded out?


Yes they are magical in the sense that they're made up, but its a good idea. An example of displayOperation() would be:
portOperation(){


`Thread: //thread instantiated if operation() app module requires special processing priority

startThread();
 
   port->svga(*attrs_variable, port_attrs);

stopThread();
 
}



The displayOperation() is hypothetically a method. It implements similar c++ funcitonality in the sense that it takes the values provided, and stores them in memory for use. So
displayOperation(read_buf, cout);
is taking the data found in read_buf and sending it out to the console, cout, which is a reserved language component. So the functional code for displayOperation() is mainly a portOperation which just gets the port sorted out, and a thread for the connection if desired.

Its hypothetically really simple, you just take the first argument of the method on the left for storing in the second argument on the right. The rest are port and path operations. :punk:/>/>/>/>

This post has been edited by jv1597: 20 February 2020 - 08:22 AM

Was This Post Helpful? 0
  • +
  • -

#11 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 20 February 2020 - 08:40 AM

Quote

How many lines of setup would your new C++ variant need to query the user and setup the same settings?


Maybe something like:
displayOperation(cout, attrs_variable); // output to console; can be called from anywhere in the operation as attrs_variable is global within comportOperation()
arrayOperation(*global_attrs_array, array_buf); // creates an array using an empty array buffer
insertOperation(global_attrs_array, attrs_variable); // inserts the values found in attrs_variable into global_attrs_array as a space-delimited array by default
arrayOperation(*input_array, array_buf); // creates an array using an empty array buffer
insertOperation(input_array, cin); // inserts from console buffer into input_array buffer; blank inputs are whitespace elements
insertOperation(global_attrs_array, input_array); // inserts data from input_array into global_attrs_array; whitespace elements skip to next element
insertOperation(port_attrs, global_attrs_array); // inserts data from newly updated global_attrs_array into port_attrs for com1 mentioned above




Corrections:
comportOperation() as mentioned in the post above is actually better as portOperation() in general as a standard
right to left code iteration is preferred for taking from args on the right and sending/storing to/in args on the left as in the above example
data structure of reserved buffers is constant and cannot be modified

Nice and simple...

This post has been edited by jv1597: 20 February 2020 - 11:46 AM

Was This Post Helpful? 0
  • +
  • -

#12 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 20 February 2020 - 11:03 AM

C-Operation-Oriented Language (COOL) :punk:/>/>

rounded-rectOperation(*okButton, x1, x1, y1, y1, x2, x2, y2, y2, fill, 242.243.244, shade, 253.254.254, 4); 
rounded-rectOperation(*cancelButton, x1, x1, y1, y1, x2, x2, y2, y2, fill, 242.243.244, shade, 253.254.254, 4);
gui-arrayOperation(*buttons_gui-array, gui-array_buf); 
insertOperation(buttons_gui-array, okButton); 
insertOperation(buttons_gui-array, cancelButton);
displayOperation(cout, buttons_gui-array); 




This snippet would fill with gray; shade with whiter-gray 4 pixels thick, create a gui array using an empty gui-array buffer, insert 2 gui elements into the array, and display gui-array elements. Rounded-rectOperation() rounds the corners of the rectangular coordinates specified. Cool! :tooth:/>/>

This post has been edited by jv1597: 20 February 2020 - 11:33 AM

Was This Post Helpful? 0
  • +
  • -

#13 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 20 February 2020 - 11:48 AM

Does anyone know how I got a -2 for reputation?
Was This Post Helpful? 0
  • +
  • -

#14 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7289
  • View blog
  • Posts: 24,666
  • Joined: 05-May 12

Re: Just dreaming...

Posted 20 February 2020 - 07:04 PM

To check your reputation, go to your profile and look at "Reputation received".

Anyway, you just repeated what you said previous about what you were expecting the IDE to do. You did not address the how that I was asking about. Consider this scenario: The user starts a brand new project and and has just a blank page. They have not even written a module yet. So what components will be listed for that module? How did it pick those components?

Now the user types in just these 4 letters to get the word: "void". What components will be listed now? How did it pick those components?

The user continues and has this in the IDE:
void main() {
    stop();
}


What components would be listed now? How did it pick those components?
Was This Post Helpful? 0
  • +
  • -

#15 jv1597   User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 166
  • Joined: 18-October 16

Re: Just dreaming...

Posted 21 February 2020 - 01:02 AM

Quote

What components would be listed now? How did it pick those components?


OOOOOhhhhh, ok, I might have gotten you mixed up. Here's how that would work:

User chooses:
File Operation Dropdown Menu

User then chooses:
Read Operation from the dropdown menu

The reference interface brings up:
std-basic::ifstream

Two specializations for common character types are also defined:

Defined in header <fstream>
Type Definition
ifstream basic_ifstream<char>
wifstream basic_ifstream<wchar_t>
iostream basic_iostream<char>
wiostream basic_iostream<wchar_t>
std::string std::basic_string<char>
std::wstring std::basic_string<wchar_t>


File Reading:
get :: extracts characters
(public member function of std::basic_istream<CharT,Traits>)

getline :: extracts characters until the given character is found
(public member function of std::basic_istream<CharT,Traits>)


Error Checking:
good :: checks if no error has occurred i.e. I/O operations are available
(public member function of std::basic_ios<CharT,Traits>)

eof :: checks if end-of-file has been reached
(public member function of std::basic_ios<CharT,Traits>)

fail :: checks if an error has occurred
(public member function of std::basic_ios<CharT,Traits>)

bad :: checks if a non-recoverable error has occurred
(public member function of std::basic_ios<CharT,Traits>)

EXAMPLE:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
    {
      cout << line << '\n';
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}




So as with any IDE it requires whatever measure of coding experience your comfortable with for your programming needs. The reference interface doesn't bring up suggestions like suggestion widgets do, it brings up only the specific set of language components you will need for the scope of the module. So if your scope is to read from a file, it wouldn't type your code for you, it pulls up the specific methods/functions you will be using for that file read scope. Most IDEs offer templates for the sake of efficiency, in case a newbie needs one to get started.

This post has been edited by jv1597: 21 February 2020 - 01:16 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3