Author Topic: How complicated is the code for Microsoft Windows?  (Read 2768 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7542
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How complicated is the code for Microsoft Windows?
« Reply #15 on: January 26, 2020, 10:03:48 AM »
I remember long long ago that people slavishly aped Petzold's code format without ever understanding it. Petzold wrote hybrid code when 16 and 32 bit API code were both being used and his code could be switched between the two.

As far as COM, it was deliberately obscure as it shut off alternative OS versions from using it but it was always a complicated mess with unnecessary overhead that few would manually code.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10546
  • Assembler is fun ;-)
    • MasmBasic
Re: How complicated is the code for Microsoft Windows?
« Reply #16 on: February 01, 2020, 12:02:37 PM »
https://www.quora.com/As-a-software-developer-what-is-the-most-inappropriate-variable-name-youve-ever-seen
Quote
When I worked for Microsoft Office, I reviewed a code change to remove offensive words from the source code, in preparation for sharing it with partners. There were no truly offensive variable names. However…

There was a developer tool that helped developers add asserts (in-line tests). Each assert was labeled with an automatically generated four letter tag. You can see how this would go wrong.

Among others, we removed asserts labeled 'nazi’, 'c*nt', and for good measure, 'bich'.
Quote
When the consultant came back from vacation the company placed an emergency call to him to come look at the code. They asked him what LVBRIP was used for and he said, “Oh, that’s the pointer to the current location in the print buffer.” They asked why it was called LVBRIP, and he, being a Music History major said, “1827 is the year Ludwig van Beethoven died.”

They fired him on the spot.
Quote
there are far over 9k calls to goto in the code. That’s not an accurate count though because there are quite a few helper functions that also call goto and those are used everywhere as well. If I were to guess you could probably calculate the calls to goto more in the range of 30k - 50k.

This is all C code that is written by a lady who was an assembly programmer and never changed her ways for 30 or more years
Quote
Not only was it a monster of spaghetti, but every single variable was named after a Marvel comic book character.

HSE

  • Member
  • *****
  • Posts: 1379
  • <AMD>< 7-32>
Re: How complicated is the code for Microsoft Windows?
« Reply #17 on: February 02, 2020, 12:47:01 AM »
 :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7542
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How complicated is the code for Microsoft Windows?
« Reply #18 on: February 02, 2020, 01:00:15 AM »
 :biggrin:

> Not only was it a monster of spaghetti

For most who have only heard of spaghetti code, its a lot harder to write than many would thinks, absolute line numbers as targets for the seriously maligned GOTO. As compiler can count lines without the programmer needing them to do so, the loss of line numbers was no big deal. Most of the whining about GOTO and labels comes from people who cannot read or design complex logic.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10546
  • Assembler is fun ;-)
    • MasmBasic
Re: How complicated is the code for Microsoft Windows?
« Reply #19 on: February 02, 2020, 01:18:46 AM »
Right. The only GOTO that I used persistently (after the first few weeks of learning) had only one purpose: Jump over an area (Print "123...") where I loaded 68000 assembly code... for GfaBasic users, GOTO was dead from 1987 onwards, over 30 years ago. Which doesn't stop the C/C++/C# gang to blame BASIC for "spaghetti monsters", of course. I get the creeps when I am forced to look at C++ sources :mrgreen:

The proggie is still working btw, using the Steem emulator. It's a blazing fast text processor, 15k lines of GfaBasic source plus 3k lines of 68k Assembly. With integrated graphics and plot facility. I've written even the printer driver, and managed to write, print and publish a book with a renommated scientific publisher. Shortly afterwards my employer forced me to switch to Windows :sad:

Siekmanski

  • Member
  • *****
  • Posts: 2330
Re: How complicated is the code for Microsoft Windows?
« Reply #20 on: February 02, 2020, 02:04:29 AM »
 :biggrin:

> I get the creeps when I am forced to look at C++ sources :mrgreen:

I share the same feeling, remember the DirectShow Video Grabber C++ conversion we played with?
Creative coders use backward thinking techniques as a strategy.

felipe

  • Member
  • *****
  • Posts: 1332
  • Eagles are just great!
Re: How complicated is the code for Microsoft Windows?
« Reply #21 on: February 02, 2020, 02:11:35 AM »
written by a lady who was an assembly programmer and never changed her ways for 30 or more years

Can't see anything wrong here... :biggrin: A lady who was an assembly programmer...was a forum member too???  :tongue:
Felipe.

caballero

  • Member
  • *****
  • Posts: 1469
  • Matrix - Noah
    • abre ojos ensamblador
Re: How complicated is the code for Microsoft Windows?
« Reply #22 on: February 02, 2020, 03:43:27 AM »
Spaghetti code is awful. Refusing at all to use gotos is stupid.
The logic of the error is hidden among the most unexpected lines of the program

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: How complicated is the code for Microsoft Windows?
« Reply #23 on: February 02, 2020, 06:37:08 AM »
gotophobia is a clear sickness.
Donald Knuth wrote an article "Structured Programming with GOTO Statements" - but most considerations apply mainly to High Level Languages. Assembly has no better alternative than using pure conditional or unconditional "GOTO", this conclusion reached the developers of MASM64 bit when decided to eliminate the WHILE and REPEAT pseudo-instructions.  Assembly is close to bare metal, who does not like bare metal will do better with an HLL.

jj2007

  • Member
  • *****
  • Posts: 10546
  • Assembler is fun ;-)
    • MasmBasic
Re: How complicated is the code for Microsoft Windows?
« Reply #24 on: February 02, 2020, 08:02:25 AM »
Spaghetti code is awful. Refusing at all to use gotos is stupid.

Agreed. But in GfaBasic at least, I never ever saw a need for GOTOs. In Assembly, I use jmp very rarely, but conditional jumps are frequent. If possible, though, I use .Repeat ... .Until, because it's fast and clear. And Switch in a WndProc is a must.

daydreamer

  • Member
  • *****
  • Posts: 1360
  • building nextdoor
Re: How complicated is the code for Microsoft Windows?
« Reply #25 on: February 02, 2020, 08:06:50 AM »
gotophobia is a clear sickness.
Donald Knuth wrote an article "Structured Programming with GOTO Statements" - but most considerations apply mainly to High Level Languages. Assembly has no better alternative than using pure conditional or unconditional "GOTO", this conclusion reached the developers of MASM64 bit when decided to eliminate the WHILE and REPEAT pseudo-instructions.  Assembly is close to bare metal, who does not like bare metal will do better with an HLL.
while and repeat are macros probably can be remade with macro caps if wanted ,not my favourite loop is forloop
still if you love to use switch/case much in C,the compiled code ends up with lots of jumps
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

morgot

  • Member
  • **
  • Posts: 75
Re: How complicated is the code for Microsoft Windows?
« Reply #26 on: February 07, 2020, 02:48:27 AM »
COM is terrible from ASM and from C/C++.
It is easy from Delphi and also from the .Net languages.
All high-level languages are simple because they hide abstraction. As an example, wininet is simpler than sockets, and the Indy components (delphi / C ++ collector) are even simpler. But a normal programmer must understand how everything works inside. Because all this is based on low-level languages. In case of an error in Masm or C, I will take a debugger and look.

But in Linux all things are simpler, that in Windows. This is fact.
p.s. in some interview i read , that microsoft programmers used LSD, when creating Windows.. It look likes true.
Sorry for the bad English

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: How complicated is the code for Microsoft Windows?
« Reply #27 on: February 07, 2020, 10:29:52 PM »
But in Linux all things are simpler, that in Windows. This is fact.

It is never a waste of time to create another Windows versus Linux war.  :biggrin:

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: How complicated is the code for Microsoft Windows?
« Reply #28 on: February 08, 2020, 12:15:13 AM »
COM is terrible from ASM and from C/C++.

I will argue there's a big difference between C and C++ with regards to COM but (at least now) the assembler interface is actually simpler than C++.

include windows.inc
include shlobj.inc

    .code

wmain proc

  local link:ptr IShellLinkW
  local file:ptr IPersistFile

    CoInitialize(NULL)
    .ifd CoCreateInstance(&CLSID_ShellLink, NULL,
            CLSCTX_INPROC_SERVER, &IID_IShellLink, &link) == S_OK

        link.QueryInterface(&IID_IPersistFile, &file)
        link.SetPath("N:\\dir\\some file that doesn't exist.txt")
        file.Save("test.lnk", TRUE)
    .endif
    xor eax,eax
    ret

wmain endp

    end

Quote
We should not try to understand in detail how it works, we will never get it...
Rule: Don't try to understand in detail, you will never get it, just learn how to obtain results.

 :biggrin:

Somewhat true as it is more complicated to create than use but it is after all one of the simplest object constructs there is. And as for the hidden abstractions it should be in range of being possible to understand.

wmain   PROC
        push    rbp                                     
        mov     rbp, rsp                               
        sub     rsp, 64                                 
        xor     ecx, ecx                               
        call    CoInitialize                           
        lea     rax, [rbp-8H]                           
        mov     qword ptr [rsp+20H], rax               
        lea     r9, [IID_IShellLinkA]                   
        mov     r8d, 1                                 
        xor     edx, edx                               
        lea     rcx, [CLSID_ShellLink]                 
        call    CoCreateInstance                       
        test    eax, eax                               
        jnz     ?_001                                   
        lea     r8, [rbp-10H]                           
        lea     rdx, [IID_IPersistFile]                 
        mov     rcx, qword ptr [rbp-8H]                 
        mov     rax, qword ptr [rcx]                   
        call    qword ptr [rax]                         
        lea     rdx, [DS0000]                           
        mov     rcx, qword ptr [rbp-8H]                 
        mov     rax, qword ptr [rcx]                   
        call    qword ptr [rax+0A0H]                   
        mov     r8d, 1                                 
        lea     rdx, [DS0001]                           
        mov     rcx, qword ptr [rbp-10H]               
        mov     rax, qword ptr [rcx]                   
        call    qword ptr [rax+30H]                     
?_001:  xor     eax, eax                               
        leave                                           
        ret                                             
wmain   ENDP

jj2007

  • Member
  • *****
  • Posts: 10546
  • Assembler is fun ;-)
    • MasmBasic
Re: How complicated is the code for Microsoft Windows?
« Reply #29 on: February 08, 2020, 12:46:41 AM »
I prefer BASIC :tongue:

include \masm32\MasmBasic\MasmBasic.inc
.code
CLSID_IExplorer         GuidFromString("0002DF01-0000-0000-C000-000000000046")  ; either use quoted text syntax or...
IID_IWebBrowser2        GuidFromString({D30C1661-CDAF-11D0-8A3E-00C04FC9E26E})  ; ... paste copied registry key name
MyBrowser proc uses edi url
LOCAL vEmpty:VARIANT, hWin, WebInterface
  ClearLocals
  lea edi, WebInterface
  pInterface equ dword ptr [edi]
  .if rv(CoCreateInstance, addr CLSID_IExplorer, NULL, CLSCTX_LOCAL_SERVER, addr IID_IWebBrowser2, edi)==S_OK
       CoInvoke pInterface, IWebBrowserVtbl.put_StatusBar, VARIANT_FALSE       ; OK, now configure the browser
       CoInvoke pInterface, IWebBrowserVtbl.put_MenuBar, VARIANT_FALSE         ; false = no menu
       CoInvoke pInterface, IWebBrowserVtbl.put_Visible, VARIANT_TRUE
       CoInvoke pInterface, IWebBrowserVtbl.get_HWND, addr hWin
       lea edx, vEmpty         ; Navigate needs pointers to four empty VARIANTS
       CoInvoke pInterface, IWebBrowserVtbl.Navigate, Ole$(url), edx, edx, edx, edx
  .endif
  ret
MyBrowser endp
  Init                          ; ## COM demo: open Internet Explorer ##
  .if rv(OleInitialize, NULL)==S_OK
        invoke MyBrowser, Chr$("http://masm32.com/board/index.php?action=unread")
        invoke OleUninitialize
  .endif
EndOfCode