3
Who is following the Sof-br saw that I asked something about pseudo-code a few hours ago (here if you want to follow the context)
Well, I need to make a pseudo-code in English that serves as a basis to implement this code in Java, C# and C++, Javascript and other languages (some already implemented).
So I ventured to make this pseudo-code, but I don’t know if it’s correct, can you tell me how to make it more righteous and befitting reality? Is that 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
If this is pseudo-code, the only thing I see wrong is that socket in English is written SOCKET with 'c'. And the program will always return
true
. I see no use in always returning the same constant value, especially when it is a primitive value as the value for true, i.e.: I can quietly ignore the return of the program because it will always end up in the same.– Oralista de Sistemas
But the structure of a pseudo-code is that right then? There is no right or wrong way to write?
– anisanwesley
There’s no such thing as "official" pseudocode, so you can’t discuss syntax or semantics. Other than that, you demonstrate how you want to assemble a data structure with clarity and precision.
– Oralista de Sistemas
hmm, thank you so much, I thought it had some pattern because I researched it and I didn’t find it, so answer that there is no pattern defined that I mark as certain.
– anisanwesley