What is wrong with this pseudo-code?

3

Someone who is following the software has seen that I have asked something about pseudo-code some hours ago here if you want to follow the context)

Well, I need to make a pseudo-code in English that will be the basis for implementing this code in Java, C # and C ++, Javascript and other languages ( some already implemented ).

So I ventured to do this pseudo-code, but I do not know if it is correct, can you tell me how to do it to make it more up-to-date and consistent with reality? That's right? What to change?

STRUCTURE TYPECONNECTION
Client 
Server
END TYPECONNECTION

VARIABLES
TypeConnection,
NetworkStream,
Writer,
Reader,
Server,
Client,
Ip,
Port
IsStarted
ENDVARIABLES

STRUCTURE SOKETSUPPORT

PROCEDURE CONFIGURE
    SWICH TypeConnection
        CASE TypeConnection is Server
            initialize server with ip and port
            start Server
        END CASE
        CASE TypeConnection is Client
            initialize client
        END CASE
    END SWICH
END CONFIGURE

RETURNS true
END CONFIGURE 

PROCEDURE SENDDATA(data)

    TRY
        IF
            SWITCH TypeConnection
                CASE TypeConnection is Server
                    write data in Writer
                    flushes writer 
                    closes soket
                END CASE    
                CASE TypeConnection is Client
                    initialize client with ip and port
                    initialize NetworkStream
                    initialize Writer
                    initialize Reader
                    IF Client is connected
                        write data in Writer
                        flushes writer
                    END IF
                END CASE
            END SWITCH
        END IF
        RETURNS IsStarted
    END TRY
    CATCH
        RETURNS false
    END CATCH

END SENDDATA

PROCEDURE RECEIVEDATA
    TRY
        IF IsStarted
        SWITCH TypeConnection
            CASE TypeConnection is server
                Accept socket
                initialize NetworkStrem with socket
                initialize Reader with NetworkStrem
                RETURNS Reader's reading
            END CASE
            CASE TypeConnection is client
                RETURNS Reader's reading
                close client
            END CASE
        END SWITCH
        END IF
    END TRY
    CATCH
        RETURNS Exception message
    END CATCH
END RECEIVEDATA

END SOKETSUPPORT
    
asked by anonymous 20.05.2014 / 21:56

1 answer

2

There is no "official" pseudo-code language. There are several different ways of expressing verbatim about how a structure should be, or how it should behave; but as pseudocode is not interpreted or compiled by a machine, any attempt to point out an error in style tends to pedantry. What is most important is that the shape of the structures and the logic of the operations are clear.

However, several programming courses try to introduce a grammar to the pseudocode, which I find somewhat forced. In these cases, I recommend following the pattern of the course, but without losing nights of sleep because of it.

    
21.05.2014 / 00:38