"untying knuth's knots: how to restructure spaghetti code?" Code Answer
Answers related to “untying knuth's knots: how to restructure spaghetti code?”
- How to run or debug php on Visual Studio Code (VSCode)
- How to get country code and currency code by IP-address? [closed]
- How to code a simple versioning system?
- How to diagnose these PHP-Code-Coverage segmentation and zend_mm_heap corrupted errors
- PHP - How to count lines of code in an application
- How to run PHP code from Visual Studio Code (VSCode)?
- how to adhere to the Don't-Repeat-Yourself (DRY) principle when there will be too many if-then-else making the code...
- How to run PHP with vscode
- how to change url structure with 301 code q2a
- How to create download link for qr code image in Laravel?
- How to turn off warnings while debugging in VS Code?
- How to configure xdebug stacktrace to link to and open files in VS Code
- How to set Apache HTTP 503 error code instead of HTTP 500 on PHP error
- How to get the PHP Code Coverage working with phpdbg on a Windows Server?
- How to restructure multi-dimensional array with columns as rows?
- How to convert PHP code to Twig code?
- How do you format code in Visual Studio Code (VSCode)?
- How to turn off the Eclipse code formatter for certain sections of Java code?
- How to prevent code injection attacks in PHP?
- how to use views in code first entity framework [closed]
- How to use Visual Studio Code as Default Editor for Git
- How to dynamically load reducers for code splitting in a Redux application?
- How to execute Python code from within Visual Studio Code
- How to disable code formatting for some part of the code using comments?
- How to compile a .NET application to native code?
- How to write html code inside <?php ?>, I want write html code within the PHP script so that it can be echoed from...
- How to declare one to one relationship using Entity Framework 4 Code First (POCO)
- How to find unused/dead code in java projects [closed]
- How to reset settings in Visual Studio Code?
- EF Code First: How to get random rows
- How to auto-format code in Eclipse?
- EF4 Code First: how to add a relationship without adding a navigation property
- How to generate a QR Code for an Android application? [closed]
- How to edit existing VS Code Snippets
- How to disable cascade delete for link tables in EF code-first?
- How to add multiple terminals in VS Code?
- how to implement regions/code collapse in javascript
- How to map table splitting in EF Code First?
- How to open Visual Studio Code from the command line on OSX?
- How to download/checkout a project from Google Code in Windows?
- Android, How to read QR code in my application?
- How to create index in Entity Framework 6.2 with code first
- How to get c code to execute hex machine code?
- How to remove child one to many related records in EF code first database?
- How to Specify Primary Key Name in EF-Code-First
- How can I add my attributes to Code-Generated Linq2Sql classes properties?
- Windows command interpreter: how to obtain exit code of first piped command
- How to convert DbSet in Entity framework to ObjectQuery
- How to access a JavaScript variable from code behind in asp.net
- How to change indentation in Visual Studio Code?
- How to do tag wrapping in VS code?
- How to decode a QR-code image in (preferably pure) Python?
- How to edit default dark theme for Visual Studio Code?
- How to get code coverage using Android Studio?
- How to store images using Entity Framework Code First CTP 5?
- Visual Studio Code - How to add multiple paths to python path?
- Entity Framework Code First : how to annotate a foreign key for a “Default” value?
- How to apply database code first migrations in an azure deployed application?
- How to change VS Code terminal selection UI from tabs back to dropdown?
- How do you format code on save in VS Code
- How to call VS Code Editor from terminal / command line
- How to Import Intellisense files into vsCode (Visual Studio Code)
- How to Seed Users and Roles with Code First Migration using Identity ASP.NET Core
- How to compare different branches in Visual Studio Code
- How to compile c# in Microsoft's new Visual Studio Code?
- How to disable IntelliSense in VS Code for Markdown?
- How to specify a user id and password for Visual Studio Code with an authenticating proxy?
- How to specify table name with Entity Framework Code First Fluent API
- how to add a code-behind page to a view or partial view
- How to customize comment block characters in visual studio code?
- How to run Java code using Java code?
- How to join multiple tables?
- How to use MS code coverage tool in command line?
- How to suppress code analysis messages for all type members?
- How to create PFX with my chain of certificates?
- How to auto-indent code in the Atom editor?
- How to create a QR code reader in a HTML5 website? [closed]
- How to collapse blocks of code in Eclipse?
- How to add new table to existing database code first
- How to show full long line in visual studio code (word wrap off)
- VS Code: How to convert snippet placeholder from camelCase to SCREAMING_SNAKE_CASE?
- How to make gcc generate only machine code that can be loaded directly into memory and executed?
- How to reset intellisense in VS Code?
- How to use custom font in visual studio code
- How to debug/break in codedom compiled code
- How to use ARM Assembly code in an Android project?
- PHP source code in UTF-8 files; how to interpret properly?
- How to map a protected property in EF 4.3 code first
- How to Set Image Resource URI from Code-Behind
- How to use pip with Visual Studio Code
- How to avoid code duplication of different structs with semantically equal fields/properties?
- How to reduce the code space for a hexadecimal ASCII chars conversion using a _small_ code space?
- How to remove code structure view or “breadcrumbs” in Visual Studio Code?
- How to format code in Xcode?
- How to change the integrated terminal in visual studio code or VSCode
- How to set the root directory for Visual Studio Code Python Extension?
- How to draw a QR code with Qt in native C/C++
- How to use multiple tsconfig files in vs-code?
- How to specify database name in Code First?
- How to hide code in RMarkdown, with option to see it
- How to disable codelens in VS code?
- How to generate code dynamically with annotations at build time in Java?
- How to view “generated HTML code” in Firefox?
- How to show graph in Visual Studio Code itself?
- How to find a similar code fragment?
- How to decode huffman code quickly?
- How to ignore a property when using Entity Framework Code First
- How to decode QR code
- How to get Entity Framework Code First and nullable foreign key properties to work?
- How to disable “just my code” setting in VSCode debugger?
- How to query Code First entities based on rowversion/timestamp value?
- How to add external assembly (.dll) to .NET Core 2.0 on Visual Studio Code
- How to write Protractor test scripts using Typescript along with Jasmine framework in Visual studio Code?
- VS Code: How to access debug variables from within extension?
- How to run Cmake in Visual Studio Code using tasks
- EF Code First 4.1 - How to configure one to many relationship with default
- How to get ListBox ItemsPanel in code behind
- EF code-first: How to load related data (parent-child-grandchild)?
- How to use OSGi fragments to contribute platform-dependent native code with the same filename?
- How to stop EF4.1 Code-First to create Culstered index for the entity PK
- How to programatically create Sql Azure database of type Basic/Standard edition through Enity Framework code first
- How do I contribute a command to the VS Code explorer title bar or command palette that is only active when my...
- How to implement QR code scanner in Fragment in portrait mode in android?
- How to detect code-coverage of separated folders in GO?
- How to collect code coverage with Istanbul when executing HTTP endpoints via Postman or Karate
- How to map foreign keys between TPH TPT objects - Entity Framework Code First
- Roslyn Code Action: How to check if preview or real execution?
- How to check for an HTTP status code of 401?
- how to add el code or jstl code through javascript
- How to restructure object of NSDictionaries
- How to indent/format a selection of code in Visual Studio Code with Ctrl + Shift + F
- How to blog code at wordpress.com [closed]
- How to debug Karma tests in Visual Studio Code?
- How to fix GCC compilation error when compiling >2 GB of code?
- How to assign a dynamic resource style in code?
- How to make QR code for BOTH Android Market and App Store [closed]
- How to search for just a specific file type in Visual Studio code?
- How to set up devices for Visual Studio Code for a Flutter emulator
- How to generate a QR Code for Google Authenticator that correctly shows Issuer displayed above the OTP?
- How to open a shell command prompt inside Visual Studio Code?
- How to find dead code in a large react project?
- How to use Delve debugger in Visual Studio Code
- Android: how to share code between projects signed with the same certificate
- How to display hidden files with Visual Studio Code
- How to trap exit code in Bash script
- jUnit: How to determine level of code coverage?
- EF code first: How to delete a row from an entity's Collection while following DDD?
- How to store double[] array to database with Entity Framework Code-First approach
- How to run the select code in VScode?
- How do I map TimeSpan with greater than 24 hours to SQL server Code First?
- How to see a SQLite database content with Visual Studio Code
- How to display Xcode code coverage when is not displaing?
- How to decorate a class as untestable for Code Coverage?
- How to create callbacks between android code and native code?
- How to display current values of VS Code's predefined variables (such as “${workspaceFolder}” or...
- How to measure Code Coverage in ASP.NET Core projects in Visual Studio?
- ASP.NET, VB: how to access controls inside a FormView from the code behind?
- How to insert jQuery code? Uncaught ReferenceError: $ is not defined in view razor code
- How to stop execution of python script in visual studio code?
- How to restructure Maven multi-module project?
- How to MAP select stored procedure in Entity Framework 6 code-first approach?
- How to open Visual Studio Code with admin privileges to make effect of the installed extensions
- How to find 'masked' assertions in MS Code Contracts
- How to avoid VS Code warning: “[myfile].java is a non-project file, only syntax errors are reported”
- How to enable Node.js code autocompletion in VSCode?
- How to customize foreign key column name using Entity Framework Code-first
- EF4 Code First: how to update specific fields only
- How to define nested Identifying Relationships Entity Framework code first
- How to use `pkg-config gtkmm-3.0 --cflags --libs` in the Visual Studio Code
- How to disable VS Code auto-rename-tag / HTML mirror feature?
- How to format code in Visual Studio Code on Windows
- How to display console.log output in Visual Studio Code for html?
- How to represent Bridge table in Entity Framework Code First
- How to build and run C++ code in Visual Studio Code?
- How to do Coverage exports for vscode extensions
- How to configure StyleCop to suppress warnings on generated code?
- How to demonstrate SQL Injection in this PHP and MySQL code?
- How to debug Django custom management command using VS Code
- How to get code-completion for COM programming in PyCharm?
- How to separate large table into multiple discrete types using EF-Code-First
- How to debug Serverless Offline in Visual Studio Code using another port?
- ReSharper - how to disable generation of rubbish documentation headers in Code Cleanup
- How to prevent insert spaces in JSX code
- How to get zip code or area code of the current location in android?
- How to scan a QR code in live mode in Blackberry OS 5
- EF4 Code First - How to properly map Splitting an Entity Across Multiple Tables
- How to correctly import a Python module in VS Code?
- How to eagerly load a many to many relationship with the entity framework code first?
- How to make HtmlSelect Control with OnChange event to trigger C# code behind function
- How to execute local bash code from VSCode extension
- How to make VS Code read Python imports without displaying yellow squigglies?
- How to write a C++ code generator that takes C++ code as input?
- How to seed identity seed value in entity framework code first for several tables
- How to manually update Entity framework Code first model so that it updates a database (with a new column)?
- How to set syntax highlighting for Dart variable in Visual Studio Code
- How to chain tasks in Visual Studio Code using only tasks.json?
- Django - http code 304, how to workaround in the testserver?
- How to check code coverage with tests for methods with specified level of complexity in Java
- Java: How to @SuppressWarnings unreachable code?
- How to reference a WSDL file using Visual Studio Code?
- How to move to the next/previous variable reference in VS Code?
- How to pass variable from jquery to code behind (C#)?
- How to have multiple one-to-many relations between two entities using Entity Framework Code First
- How to add a new project to Github using VS Code
- Is there a way to avoid spaghetti code over the years? [closed]
- DDD with EF Code First - how to put them together?
- How to add a string to the end of each line in VS Code using regex?
- How to remote debug python code in a Docker Container with VS Code
- How to properly use Code Contracts in .NET Core
- VS Code: How to convert snippet placeholder to uppercase or lowercase?
- How to use custom font in VS Code(Windows) without admin privilege to install the font?
- How to force MSBuild to run Code Analysis without recompiling
- How to organise large code files?
- How to migrate code to null safety in Dart
- How to make VS Code change language to JavaScript React when open a JSX file
- How to make Eclipse to format JSP code properly?
- How to use GitHub code navigation from browser?
- How to refer to current file from Integrated Terminal in Visual Studio Code
- How do I use code contracts in .NET 4.0 without making my code look cluttered?
- How to run assembly code without creating a new process?
- How to avoid repeated code?
- How to disable Eclipse CDT code formatter for a code block
- How to add a code snippet to method body with JDT/AST
- How to connect Visual Studio Code to Visual Studio Team Services
- How to force Emma code coverage report to ignore some methods?
- How to update VS Code on Windows?
- How to make VS Code's auto-complete more strict?
- How to create VS Code extension that provides custom problemMatcher?
- How to store reusable code in Visual Studio 2010?
- How to get 100% code coverage in Golang?
- How to show QR code scan progress with the moving line indicator?
- In Visual Studio 2013 how do I limit code analysis to my code and not to referenced assemblies?
- How to get code from google code?
- How to make VS Code Autocomplete Python Class Attribute Initialization
- How to sign code (.EXE file) with a .SPC or .PEM file from GoDaddy (using Ubuntu)? [closed]
- How to run machine code as a function in c++
- Ruby Rails: How to generate QR code images in different color
- How to get QR code from id?
- Dead code and/or how to generate a cross reference from Haskell source
- How to configure Visual studio code to use standard tab switching shortcut for mac?
- How to check minimum code coverage for multi-module maven project with jacoco?
- Laravel 5.2 How To redirect All 404 Errors to Homepage
- Using vs code, how to get scala format to work and format my code?
- How to convert C# code that uses Shell COM to F#?
- Running python script in Visual Studio Code; how to get `input ()` to work?
- How to Get Full Object with Code First Entity Framework 4.1
- How to create a nested GridView to edit EF Code First relation?
- Netbeans code-gen woes: How to edit auto generated code?
- How to convert a Uri to a FilePath in a VS Code Language Server?
- How to run VS Code on Android Device
Only authorized users can answer the Search term. Please sign in first, or register a free account.
i sketched an algorithm for op earlier at https:///a/36661381/120163
found a better paper that discusses how to generate structured code while preserving the original control flow graph exactly:
w.d maurer, "generalized structured programs and loop trees", science of computer programming, 2007
i followed that procedure (on paper, hope i did it right, looks ok at 2:40 am). his basic trick is to find strongly connected regions (cycles in the code); these will become loops; he then breaks that cycle by deleting an edge; this eventually becomes a loop backlink (restored when he is complete). the process is repeated until no more cycles can be found; what is left is essentially a structured program with identified loops. it is tricky to do this right; you really need an automated procedure. your bit of code, although small, is still pretty nasty :-}
i cheated in one place. maurer insists that forward gotos are ok, even into the middle of loop. if you buy that, then you can preserve the cfg exactly. if not, you have to handle the case where a loop has two or more entry points; your algorithm has such a loop. i solved the problem by coding the loop, and coding a loop-tail-end-fragment equivalent that acts like the first iteration of jump-into-the-middle, which is followed by the loop itself.
my notation is a little funny: most languages don't have "block{...}" constructs. [the one i code in (see bio) does]. think of this as being an "execute one iteration" loop :-} i assume that blocks/loops have loop exits and loop continues. if you dont have these, you can simulate them with sufficient quantity of just block{ ... } and exit_block@n.
edit after accepted: in the light of day, i didn't do it right, i left out the of the while loop@3. i've patched that; the need for the block construct now goes away because i can exit the while loop@3 to achieve the same affect. actually, the code reads a little better.
i left your numeric labels in, even where they aren't needed, for easier reference.
unlike most other answers i've seen so far, this runs at the same speed as the original (no extra flags or flag checks).
@hatchet's answer is interesting; a) it is equally fast, b) he chose to handle the two entry loop by the same technique, but he chose the "other entry" as the loop top. he did something similar with the "enter_level(k)" operation at label 2.
it is interesting that all this structuring doesn't seem to help readability of this code one bit. makes one wonder about the whole point of "structured programs". maybe well-designed spaghetti isn't so bad :-}