• Welcome to the new Internet Infidels Discussion Board, formerly Talk Freethought.

The Programming Thread

GUI builders: software for laying out GUI widgets, like placement of buttons, text fields, etc. in windows. GUI widgets, a.k.a. GUI controls or GUI elements.

For MacOS Classic, I used ResEdit, which creates a "resource file" with GUI definitions. The original Macintosh team discovered that 128K of memory was very low for GUI's, so they decided on giving each file a "data fork" and a "resource fork". The data fork is an uninterpreted string of bytes, like for Unix and DOS and Windows. The resource fork is a mini-database, with the contents labeled by a 4-byte typecode and a 16-bit number. The resource fork was used for GUI definitions and app graphics, and also for executable code. The resource-fork access was designed so that resource data loaded into memory could easily be purged from memory to make way for other resource data.

For MacOS Cocoa, I use Interface Builder, originally separate from the IDE, Project Builder, but now included in it in one app, Xcode. IB has the nice feature that one can "wire" an app, connecting GUI widgets to placeholder objects in it. In one's code, one prefaces references to GUI widgets with "IBOutlet" and functions that do GUI-widget actions with "IBAction". One then wires from placeholder to widget and selects which IBOutlet one wants, and from widget to placeholder and selects what IBAction one wants. One can also do widget-to-widget connections, like for specifying which order one wants to tab through some text fields.

Programmatic: specifying all the GUI widgets in one's code. I've had to do that with Java AWT, Android, Python/TK, and HTML/CSS/JavaScript.
 
I like this anecdote.
If I had to guess, I would say that the HN crowd is not fond of unverified claim... | Hacker News
From Aaron Hillegass Cocoa® Programming for Mac® OS X, Third Edition

Once upon a time, there was a company called Taligent, which was created by IBM and Apple to develop a set of tools and libraries like Cocoa. About the time Taligent reached the peak of its mindshare, I met one of its engineers at a trade show. I asked him to create a simple application for me: A window would appear with a button, and when the button was clicked, the words “Hello, World!” would appear in a text field. The engineer created a project and started subclassing madly: subclassing the window and the button and the event handler. Then he started generating code: dozens of lines to get the button and the text field onto the window. After 45 minutes, I had to leave. The app still did not work. That day, I knew that the company was doomed. A couple of years later, Taligent quietly closed its doors forever.
 Taligent lasted 1992 - 1998.
 
Nothing current.

With the old Borderland C/C++ it was easy to create a GUI. It had extensions for it.

Library functions to read cursor positions. Functions to create and format a window.

If you used MS tools you had to learn the Foudarion classes. A lot of work. If you ordered the MS documentation you got a couple of boxes filled with books. There may have been an MS certifications you could get.

I had the current MS Visual C++ tools running until I had to create an account to keep it running.

It is still not simple to create a hello world window with a button. You have to go through a learning curve. To get the documentation you have to pay a lot of money to MS.

Visual Basic might be easier.
 
FYI. I use Code Blocks to play around with C++. This is a base win32 app created by Code Blocks. It creates a window and does nothing else.


Code:
#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Code::Blocks Template Windows App"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

The tool can create stand alone console apps essenially a DOS window, in which yu can display and enter data but no GUI.
 
Another issue is how to do development. Typing and retyping and retyping the build commands quickly gets old, even with history-remembering and autocompleting command-line shells.

A common solution is the Unix "make" utility and similar utilities. For make, one creates a "makefile" that contains sets of:

Target: dependencies
Build command for that target

One can also define variables, for such things as not repeating build options.

For GUI systems, there are Integrated Development Environments (IDE's).

I recall once using Borland's IDE for Windows, though that was long ago.

But I remember using Metrowerks CodeWarrior a lot for MacOS Classic in the 1990's, and I was disappointed that it didn't carry over into MacOS X. I then used Apple's Project Builder and Interface Builder, then their combination, Xcode.

I also once used Eclipse, an IDE for Android. It included an emulator of Android devices.

Are there any good IDE's for Linux?
 
I was never a Windows expert, my applications had a narrow scope.

In Code Blocks I use the GCC compiler. The IDE creates a make file that contains all the compiler and linker commands. You can edit it or make a standalone make file

A DOS window batch file should work if you are invoking the compiler and linker at the command line level. Assuming you are using Windows.

The IDEs look at your source file list and any object files to link to and create the make file.

If you are doing any kind of serious Windows work you may want to bite the bullet and buy an MS Visual Studio license. That is what I would do. It can save you a lot of time and frustration.

MS used to have a perpetual community free version. Now after a few months you have to create an MS account to use it. It is still free.

I did a test system app in Unix and used Xwindows a long long time ago in a galaxy far far away.

There are altenatves to Viul Studio that are used to do production work, I am not familiar with them.
 
I was curious if anyone else had any experience with GUI programming that they might want to share.

Like GUI builders vs. programmatic GUI's.
Ah. No experience I particularly want to share. It's a fun problem to solve the truth and logic framework for, and a really boring framework to actually apply, for me.

It's just defining polygons and logic for "is inside" arranged and indexed in some way, and then collecting the tracked position of elements to provide the input to "is inside" or to dequeue keypresses and determine the intersections of "downness" and the edge orderings, and arranging callbacks on various named detection models when that downness corresponds to a schedule execution in the downness of an interrupt.

In application, once the framework to do the math is laid down, actually operating it is just so boring.
Another issue is how to do development. Typing and retyping and retyping the build commands quickly gets old, even with history-remembering and autocompleting command-line shells.

A common solution is the Unix "make" utility and similar utilities. For make, one creates a "makefile" that contains sets of:

Target: dependencies
Build command for that target

One can also define variables, for such things as not repeating build options.

For GUI systems, there are Integrated Development Environments (IDE's).

I recall once using Borland's IDE for Windows, though that was long ago.

But I remember using Metrowerks CodeWarrior a lot for MacOS Classic in the 1990's, and I was disappointed that it didn't carry over into MacOS X. I then used Apple's Project Builder and Interface Builder, then their combination, Xcode.

I also once used Eclipse, an IDE for Android. It included an emulator of Android devices.

Are there any good IDE's for Linux?
There are, notably the QT suite, particularly for embedded applications. The QT framework also creates some modeled classes and the accessibility of limited object model reflection normally only seen in more "scripty" languages like Java and C#.

There are a lot of really dumb elements where it steps away from simple POSIX machines in ways that make it easy to break for low level operations which are really best left in that space of user managed mutexes and semaphores: if it's not broke don't fix it.

Still QT is mostly serviceable as a Linux framework and IDE.
 
I always hated to periodically reinvent the wheel and coded tasks as much as I could.

This is the log file for a Code Blocks build. The first gcc run crtes the object file, the seond crates the executable. The second section runes the .exe in a DOS window, renamed PowerShell.

gcc.exe -Wall -g -std=c17 -c C:\Users\Documents\CodeBlock\misc\disa2\main.c -o obj\Debug\main.o
gcc.exe -o bin\Debug\disa2.exe obj\Debug\main.o
Output file is bin\Debug\disa2.exe with size 53.93 KB

Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

-------------- Run: Debug in disa2 (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\Users\Documents\CodeBlock\misc\disa2\bin\Debug\disa2.exe
Set variable: PATH=.;C:\MinGW\bin;C:\MinGW;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\AppData\Local\Microsoft\WindowsApps
Executing: "C:\Program Files\CodeBlocks/cb_console_runner.exe" "C:\Users\Documents\CodeBlock\misc\disa2\bin\Debug\disa2.exe" (in C:\Users\Documents\CodeBlock\misc\disa2\.)

Process terminated with status -1073741510 (0 minute(s), 3 second(s))

The IDE builds command strings knowing the particular compiler. The command can be executed using the system() function.

The code reads the source and destination file paths from a text file and builds a compiler command string.

IDEs including MS can create console apps. To run a console app there is a Windows dll that needs to be in the same directory as the .exe.


Code:
int main(void)
{
    string gcc1 = "gcc.exe -Wall -g -std=c17 -c ";
    string gcc2 = " -o ";
    string obj_path;
    string source_path;
    string file_name = "project.txt";
    ifstream in_file;
    in_file.open(file_name);
    in_file >> obj_path;
    in_file >> source_path;
    in_file.close();
    string gcc_cmd = gcc1 + source_path + gcc2 + obj_path;
    system(gcc_cmd);
    cout << gcc_cmd << "\n";
    return 0;
}


project.rxr
c:/project/obj/code.o
c:/project/code.cpp
 
For me this was just background info. It is used in computer science. Tutorials are online. Compiler design.



In computer science, Backus–Naur form (/ˌbækəs ˈnaʊər/) or Backus normal form (BNF) is a metasyntax notation for context-free grammars, often used to describe the syntax of languages used in computing, such as computer programming languages, document formats, instruction sets and communication protocols. It is applied wherever exact descriptions of languages are needed: for instance, in official language specifications, in manuals, and in textbooks on programming language theory.

Many extensions and variants of the original Backus–Naur notation are used; some are exactly defined, including extended Backus–Naur form (EBNF) and augmented Backus–Naur form (ABNF).



In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form

A → α A\ \to \ \alpha

with A A a single nonterminal symbol, and α \alpha a string of terminals and/or nonterminals ( α \alpha can be empty). A formal grammar is "context-free" if its production rules can be applied regardless of the context of a nonterminal. No matter which symbols surround it, the single nonterminal on the left hand side can always be replaced by the right hand side. This is what distinguishes it from a context-sensitive grammar.

A formal grammar is essentially a set of production rules that describe all possible strings in a given formal language. Production rules are simple replacements. For example, the first rule in the picture,

⟨ Stmt ⟩ → ⟨ Id ⟩ = ⟨ Expr ⟩ ; {\displaystyle \langle {\text{Stmt}}\rangle \to \langle {\text{Id}}\rangle =\langle {\text{Expr}}\rangle ;}
 
Code::Blocks - Code::Blocks - "The free C/C++ and Fortran IDE."
 Code::Blocks
Available for all three major desktop platforms.

Has anyone here used it?
I was using Visual Studio until MS required logging on to MS before using it.

I switched to Code Blocks.

It works fine and is easy to use. I tres eclpse as well but went with Code Blocks. It is a small version of the Visual Studio environment

All my Visual C++ code ran on CB. If you select the C/C++ standard versions then code will be portable.

As to GUI, CB like Visual Stdio will create a generic project with Windows basic code, but you still need to know the widows GUI structures and how ro use them.

In Scilab when I create a graphics object a set of objects with the window properties accessed as an object with the widow handle. Same gnerl principal with Windows.


The code I posted in #204 was created by CB when creating a new GUI project, Visual Studio does the same.

CB has a debugger and variable tracker.

It supports multiple compilers and math libraries.

There are online tutorials and apparently CB is common in college courses.

I am not a widows expert but I can help you get a first project going in CB.
 
1. Install Code Blocks
2. Create a CodeBlocks folder for your projects. I have a misc folder for odd projects.
3. From the CB program files folder copy the MINGW folder to the C: root directory.
4. Start CB
5. new→project→ console app
6. Select c or C++
7. Enter a project name and select a project folder.
8. Select debug and release.
9. When the project opens select the main.cpp file from the project tree window to see the code.
10. build -> build
11. build -> run
12. A window with hello world should pop up.

When the project is n the debug mode it inserts code for things like breakpoints abd single stepping.
In release mode it removes debug code.
 
Processor speed these days is genlly noy an issue for genral computing. For embede apps and regular coding it can be useful to crreate a tailored math librayr. A small enbed app may only need pne or ytwo trig functions.

Processors can have fast single cycle hardware multipliers. Repetitive division can be slow. For sin and cos a table of invwerse factorials is created to change division to multiplication. It also eliminates the factorial multiplications.

You only need the number of terms to support required accuracy.

10 terms is accurate to 8 decimal places at 45 degrees(pi/4).

sin x = x – x^3/3! + x^5/5! – x^7/7! + x^/9!….
cos x = 1 – x^2/2! + x^4/4! – x^6/6! + x^/8!….

Code:
void make_tables(int n, double *x, double *y){
    // create a table of factorials and inverse
    double fact = 1, i = 1;
    int j = 0;
    for(j = 0; j < n; j++){
        fact = fact * i++;
        x[j] = fact;
        y[j] = 1./fact;
    }//j

}//make_tables()

double _sin(int n_terms, double ang, double *k){
    int i = 0, ex = 1, j = 0;
    double sin_val = ang;
    for(i = 0; i < n_terms;i++){
        sin_val -= k[j += 2]*pow(ang,ex += 2);
        sin_val += k[j += 2]*pow(ang,ex += 2);
    }//i
    return(sin_val);
}//_sin()

double _cos(int n_terms, double ang, double *k){
    int i = 0, ex = 0, j = -1;
    double cos_val = 1;
    for(i = 0; i < n_terms;i++){
        cos_val -= k[j += 2]*pow(ang,ex += 2);
        cos_val += k[j += 2]*pow(ang,ex += 2);
    }//i
    return(cos_val);
}//cos()

int main()
{
    int n = 10;
    double *fac = new double[n];
    double *fac_inv = new double[n];
    double ang = _PI/4., val = 0;
    make_tables(n,fac,fac_inv);
    val = _sin(n,ang,fac_inv);
    printf("angle %3.3f sin %1.10f \n",180*ang/_PI,val);
    val = _cos(n,ang,fac_inv);
    printf("angle %3.3f cos %1.10f \n",180*ang/_PI,val);
    return 0;
}
 
10 terms is accurate to 8 decimal places at 45 degrees(pi/4).

sin x = x – x^3/3! + x^5/5! – x^7/7! + x^/9!….
cos x = 1 – x^2/2! + x^4/4! – x^6/6! + x^/8!….
That's not how sinus and cosinus are caclulated.
And in general Taylor expansion is not used in calculations.
 
I get the impression that a lot of the most interesting programming happens on embedded systems, where resources are highly constrained and there is a big incentive to make programs as lean and efficient as possible.

I'm reminded of John Carmack's fast inverse square root function. It's a pretty cool example of using various tricks to create a function that minimises execution time by calculating an approximate result, and does so with a couple of nifty tricks.



C:
float Q_rsqrt( float number )
{
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;    // evil floating point bit level hacking
    i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
    y  = * ( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
 // y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration,
                                              // this can be removed

    return y;
}
 
With the old 8 bit microcontrollers triming a few bytes sometimes meant getting it to fit into memory. Like the 8051. Same with optimizing for speed.

Many apps use embedded Windows or Linux. Enough room in memory to run standard C and math libraries.

I am just doodling to stay active and not forget everything.

For trig functions in an embedded app I once used lookup tables.

There are two or tree math libries optimized over time tracing back to FORTRAN that show up in software. Intel has a free math library optimized for their processors.

A lot of work has gone into numeral methods, a good example is the Fast Fourier Transform.
 
The most interesting aspect of my job is the business analysis aspect. The actual code I write is often trivial, but the business processes behind the code can be interesting.

I'd take an interesting business over an interesting tech stack.
 
The most interesting aspect of my job is the business analysis aspect. The actual code I write is often trivial, but the business processes behind the code can be interesting.

I'd take an interesting business over an interesting tech stack.
For me once I had experience the interesting part was mostly figuring out the process.
 
The most interesting aspect of my job is the business analysis aspect. The actual code I write is often trivial, but the business processes behind the code can be interesting.

I'd take an interesting business over an interesting tech stack.

I was hired onto a team that was already halfway through the app development process, and so much of the business logic code has already been done. I often have to spend several hours just reading code or doing DB queries etc. just to figure out what the code is doing before I change one or two lines.

I don't get to do much business analysis - we have dedicated BA's who do that part - but I enjoy the process of analysing the implementation to understand the hows and whys. And the BAs still have no idea how to actually code, so translating requirements in to code is itself an interesting exercise.

I find it satisfying when I get to a ticket that requires me to write or rewrite a whole feature. I don't particularly like the languages that I have to work with, but coding is fundamentally an enjoyable craft for me.
 
The most interesting aspect of my job is the business analysis aspect. The actual code I write is often trivial, but the business processes behind the code can be interesting.

I'd take an interesting business over an interesting tech stack.

I was hired onto a team that was already halfway through the app development process, and so much of the business logic code has already been done. I often have to spend several hours just reading code or doing DB queries etc. just to figure out what the code is doing before I change one or two lines.

I don't get to do much business analysis - we have dedicated BA's who do that part - but I enjoy the process of analysing the implementation to understand the hows and whys. And the BAs still have no idea how to actually code, so translating requirements in to code is itself an interesting exercise.

I find it satisfying when I get to a ticket that requires me to write or rewrite a whole feature. I don't particularly like the languages that I have to work with, but coding is fundamentally an enjoyable craft for me.
I get that.

My favorite part about coding is taking a really dense statement and exploding it bit by bit unto a semantic completion in terms of well defined operations.

It's like putting a sponge trapped in a gelatin capsule into water and watching it expand.

Pretty much anything you can say "discuss this in more concrete terms", I like to describe in more concrete terms.

One of my favorite, but rare activities (it takes me hours or days to spin up on it properly) is to take some high level operation and figure out the boolean logic that describes it.

As opposed to debugging something which is more "something is subtly wrong, go find it."
 
Back
Top Bottom