K
K
kolomiec_artiom2019-09-24 13:38:41
Programming
kolomiec_artiom, 2019-09-24 13:38:41

Why is there no dead code in structured programming?

One of the advantages of structured programming is the absence of dead code. I just can't figure out why it can't be there? Especially at the stage of modification.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hack504, 2019-09-24
@hack504

And can anyone give a clear definition of "Structured Programming" and "dead code"? After all, these are just reflections on the topic, so to speak, an abstract vision of programming in general, but how it materialized in specific programming languages ​​and how complete it is is not important, since this does not apply to the problems of the approach itself. On the contrary, this is the problem of the man himself, who is constantly looking for the golden grail that will solve all his problems, and there is always a messiah showing the way to him.
--------
And in general why climb into the theory of programming? To develop your own AP? At the applied level, this infa is nothing more than fiction.

A
ArgosX, 2019-09-24
@ArgosX

Well, usually a top-down approach. And this approach dictates the programmer to go through the entire code, removing the dead code. Let's just say - more often you have to sort through the code and, as a rule, there is much less garbage

V
vvmtutby, 2019-09-24
@vvmtutby

One of the advantages of structured programming is the absence of dead code.
I just can't figure out why it can't be there?

True for "hard" s.p. without hidden forms GOTO : BREAK , EXIT , RETURN from the "middle" of functions
On the other hand: never called functions, etc. can "take place".
I would replace the word "absence" with "helps to avoid"
PS
@Rsa97 say:
Come on...
if (false) {
... сюда никогда не попадём
}

for (i = 0; i < 0; i++) {
... и сюда тоже
}

1) See above
can "take place" / "helps to avoid"
2) Wouldn't it be difficult to rewrite "for (i = 0; i < 0; i++)" to ADA / Modula-3 ?
(thought experiment)
3) On the topic "if (false)"
"Hard structured programming" implies evidence-based programming (ADA SPARK) See
sample:
https://ironsides.martincarlisle.com/process_dns_request.adb
Counter := 1;
         Additional_Count := 0;
         while Counter <= NumFound and Additional_Count < DNS_Types.Unsigned_Short'Last-DNS_Types.Unsigned_Short(
               2*Rr_Type.MaxNumRecords) loop
            --# assert Counter >= 1 and Counter<=NumFound and
            --#    (for all Z in RR_Type.ReturnedRecordsIndexType =>
            --#       (Qname_Locations(Z) >= 0 and Qname_Locations(Z) < 16384)) and
            --#    Qname_Location >=0 and Qname_Location <= 16383 and
            --#    Answer_Count >=0 and Answer_Count <= 65535 and
            --#    Additional_Count >= 0 and
            --#    Additional_Count < DNS_Types.Unsigned_Short'Last-DNS_Types.Unsigned_Short(
            --#    2*Rr_Type.MaxNumRecords) and
            --#    NumFound >= 0 and NumFound <= rr_type.MaxNumRecords and
            --#    Integer(Output_Bytes) >= DNS_Types.Header_Bits/8+1 and
            --#    Integer(Output_Bytes) <= DNS_Types.Packet_Size;
            Start_Byte := DNS_Types.Packet_Bytes_Range(Integer(Output_Bytes) -
               DNS_Types.Header_Bits/8);
            Create_Response_A(
               Start_Byte     => Start_Byte,
               Domainname     => NS_Replies(Counter).nameserver,
               Qname_Location => Qname_Locations(Counter),
               Output_Packet  => Output_Packet,
               Answer_Count   => Additional_Count,
               Output_Bytes   => Output_Bytes);
            Start_Byte := DNS_Types.Packet_Bytes_Range(Integer(Output_Bytes) -
               DNS_Types.Header_Bits/8);
            Create_Response_AAAA(
               Start_Byte     => Start_Byte,
               Domainname     => NS_Replies(Counter).nameserver,
               Qname_Location => Qname_Locations(Counter),
               Output_Packet  => Output_Packet,
               Answer_Count   => Additional_Count,
               Output_Bytes   => Output_Bytes);
            Counter := Counter + 1;
         end loop;
      else
         Protected_SPARK_IO_05.SPARK_IO_PO.Put_Line(Protected_SPARK_IO_05.SPARK_IO_PO.Standard_Output,"bad query type", 0);
--            ada.text_io.put_line("qc: " & dns_types.Query_Type'image(Query_Type));
         Create_Response_Error(
            Input_Bytes   => Input_Bytes,
            Output_Packet => Output_Packet,
            Output_Bytes  => Output_Bytes);
      end if;

      -- this assert helps with the VCG Heap overflow
      --# assert
      --#    Answer_Count >=0 and Answer_Count <= 65535 and
      --#    Qname_Location >=0 and Qname_Location < 16384 and
      --#    Additional_Count >= 0 and
      --#    NumFound >= 0 and NumFound <= rr_type.MaxNumRecords and
      --#    Integer(Output_Bytes) >= DNS_Types.Header_Bits/8+1 and
      --#    Integer(Output_Bytes) <= DNS_Types.Packet_Size;

      DNSSEC := False;
      Max_Transmit := DNS_Types.UDP_Max_Size;
      -- Handle EDNS additional OPT record here!
      if Input_Packet.Header.QDCount = 1 and
         Input_Packet.Header.ARCount = 1 and
         Additional_Count < DNS_Types.Unsigned_Short'Last then
         Start_Byte := DNS_Types.Packet_Bytes_Range(Integer(Output_Bytes) -
            DNS_Types.Header_Bits/8);
         Create_Response_EDNS(
            Input_Packet     => Input_Packet,
            Input_Bytes      => Input_Bytes,
            Query_End_Byte   => Query_End_Byte,
            Start_Byte       => Start_Byte,
            Output_Packet    => Output_Packet,
            Output_Bytes     => Output_Bytes,
            Additional_Count => Additional_Count,
            DNSSEC           => DNSSEC,
            Max_Transmit     => Max_Transmit);
      elsif Input_Packet.Header.QDCount /= 1 then
         Protected_SPARK_IO_05.SPARK_IO_PO.Put_Line(Protected_SPARK_IO_05.SPARK_IO_PO.Standard_Output,"query count > 1", 0);
      elsif Input_Packet.Header.ARCount > 1 then
         Protected_SPARK_IO_05.SPARK_IO_PO.Put_Line(Protected_SPARK_IO_05.SPARK_IO_PO.Standard_Output,"ar count > 1", 0);
      end if;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question