Click here to Skip to main content
15,891,708 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: RIP Mark Sanborn Pin
dandy7226-Oct-21 8:27
dandy7226-Oct-21 8:27 
GeneralRe: RIP Mark Sanborn Pin
Jörgen Andersson26-Oct-21 9:29
professionalJörgen Andersson26-Oct-21 9:29 
GeneralRe: RIP Mark Sanborn Pin
  Forogar  26-Oct-21 9:32
professional  Forogar  26-Oct-21 9:32 
AnswerRe: RIP Mark Sanborn Pin
Member 1532961326-Oct-21 9:51
Member 1532961326-Oct-21 9:51 
GeneralRe: RIP Mark Sanborn Pin
englebart26-Oct-21 10:26
professionalenglebart26-Oct-21 10:26 
QuestionRe: RIP Mark Sanborn Pin
Eddy Vluggen26-Oct-21 12:14
professionalEddy Vluggen26-Oct-21 12:14 
GeneralRe: RIP Mark Sanborn Pin
den2k8826-Oct-21 23:34
professionalden2k8826-Oct-21 23:34 
PraiseI just figured out how to do code synthesis (i think)! Pin
honey the codewitch26-Oct-21 6:03
mvahoney the codewitch26-Oct-21 6:03 
Okay, so "code synthesis" (what I've heard it called in newsgroups and such but i don't know if there's an official term) is the process of generating code that - to put it simply - looks more like code a human would write than code that is generated.

For example:

C#
        // q0
            if(ch == '\"') {
                ch = _FetchNextInput(cursor);
                if(ch == -1)
                    return false;
                goto q1;
            }
            return false;
        q1:
            if((ch >= '\0' && ch <= '!') || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 1114111)) {
                ch = _FetchNextInput(cursor);
                if(ch == -1)
                    return false;
                goto q1;
            }
            if(ch == '\"') {
                ch = _FetchNextInput(cursor);
                if(ch == -1)
                    return true;
                goto q2;
            }
            if(ch == '\\') {
                ch = _FetchNextInput(cursor);
                if(ch == -1)
                    return false;
                goto q3;
            }
            return false;
        q2:
            return false;
        q3:
            if((ch >= '\0' && ch <= '!') || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 1114111)) {
                ch = _FetchNextInput(cursor);
                if(ch == -1)
                    return false;
                goto q1;
            }
            ...
            return false;
...


Forgive me for the long example, but I couldn't think of a shorter one that I had on hand that would serve. It's not the complete code, but you can see it's generated goto tables, and if you squint you can see they match text.

Humans wouldn't have written code like this - at least not typically, and without enough caffiene.

Anyway, check out just under q1:
C#
q1:
    if((ch >= '\0' && ch <= '!') || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 1114111)) {
        ch = _FetchNextInput(cursor);
        if(ch == -1)
            return false;
        goto q1;
    }


that could be
C#
q1:
    while((ch >= '\0' && ch <= '!') || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 1114111)) {
        ch = _FetchNextInput(cursor);
        if(ch == -1) // <-- could be eliminated as well
            return false;
    }
...


And then I find other opportunities to "collapse" code by similarly examining the flow (which i already have state diagrams for in this case, but in the general case you'd build some sort of flow diagram over your generated bits like that and work with it), and then i do it over and over again until there are no more changes to the code/flow

This could yield some pretty cool results. It's nowhere near an article yet. Just an idea I had this morning while working on an update to Reggie.
Real programmers use butterflies

GeneralRe: I just figured out how to do code synthesis (i think)! Pin
PIEBALDconsult26-Oct-21 6:07
mvePIEBALDconsult26-Oct-21 6:07 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
honey the codewitch26-Oct-21 6:14
mvahoney the codewitch26-Oct-21 6:14 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
PIEBALDconsult26-Oct-21 6:27
mvePIEBALDconsult26-Oct-21 6:27 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
Greg Utas26-Oct-21 6:35
professionalGreg Utas26-Oct-21 6:35 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
honey the codewitch26-Oct-21 7:01
mvahoney the codewitch26-Oct-21 7:01 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
Jörgen Andersson26-Oct-21 9:32
professionalJörgen Andersson26-Oct-21 9:32 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
honey the codewitch26-Oct-21 9:34
mvahoney the codewitch26-Oct-21 9:34 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
Jörgen Andersson26-Oct-21 9:36
professionalJörgen Andersson26-Oct-21 9:36 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
trønderen26-Oct-21 11:10
trønderen26-Oct-21 11:10 
AnswerRe: I just figured out how to do code synthesis (i think)! Pin
Eddy Vluggen26-Oct-21 13:58
professionalEddy Vluggen26-Oct-21 13:58 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
Nelek26-Oct-21 22:49
protectorNelek26-Oct-21 22:49 
GeneralRe: I just figured out how to do code synthesis (i think)! Pin
Eddy Vluggen26-Oct-21 12:19
professionalEddy Vluggen26-Oct-21 12:19 
GeneralBlast from the past Pin
Mike Hankey26-Oct-21 5:09
mveMike Hankey26-Oct-21 5:09 
GeneralRe: Blast from the past PinPopular
Greg Utas26-Oct-21 5:13
professionalGreg Utas26-Oct-21 5:13 
PraiseRe: Blast from the past Pin
Eddy Vluggen26-Oct-21 12:26
professionalEddy Vluggen26-Oct-21 12:26 
GeneralRe: Blast from the past Pin
PIEBALDconsult26-Oct-21 5:15
mvePIEBALDconsult26-Oct-21 5:15 
GeneralRe: Blast from the past Pin
dandy7226-Oct-21 6:15
dandy7226-Oct-21 6:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.