I just wrote this...

Pages: 12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-(void) handleCommand: (NSString *) command{
    if ([command length] <= 4)
        return;
    if ([command characterAtIndex:1] == '[' && [command characterAtIndex:[command length] - 2] == ']'){
        command = [command substringWithRange:NSMakeRange(2, [command length] - 4)];
	if ([command isEqualToString: @"uname"]){
		[connection sendString: [self makeCommand:[NSString stringWithFormat:@"%c:%@",'n',username]]];
	}
	else if ([command isEqualToString: @"UDID"]){
		[connection sendString: [self makeCommand: [NSString stringWithFormat: @"%c:%@",'u',[[UIDevice currentDevice] uniqueIdentifier]]]];
	}
    else if ([command isEqualToString: @"reconnect"]){
        NSLog(@"reconnectioninitiated");
        [connection closeSocket];
        NSLog(@"connecting to %@:%@",[settings objectForKey:@"server"],[settings objectForKey: @"port"]);
        
        [connection connectTo:[settings objectForKey:@"server"] withPort:[settings objectForKey: @"port"]];
    
        if (![connection isConnected]){
            NSArray *tarray = [NSArray arrayWithObjects:@"There has been an error... Please use the email button in the help menu and notify me!! If you continue to have problems connecting, there may be a fix at (ultifinitus.blogspot.com) or (http://www.facebook.com/pages/Ultifinitech/188161037870298) I'll fix this as soon as possible! you may also send me a text at : ((801) 449-0799), for now, defaults are being restored.",@"ERROR",nil];
            [self performSelectorOnMainThread: @selector(appendTextFieldWithOptions:) withObject:tarray waitUntilDone:NO];
            [self performSelectorOnMainThread:@selector(loadDefaultSettings) withObject:nil waitUntilDone:NO];
        }
    }
    else if ([[command substringToIndex:6] isEqualToString:@"change"]){
        int a = 6;
        while (a < [command length] && [command characterAtIndex:a] != '('){
            a++;
        }
        int b = a;
        while (b < [command length] && [command characterAtIndex:b] != ')'){
            b++;
        }
        int c = b;
        while (c < [command length] && [command characterAtIndex:c] != '('){
            c++;
        }
        int d = c;
        while (d < [command length] && [command characterAtIndex:d] != ')'){
            d++;
        }
        if (a < b && c < d){
                [settings setObject:[command substringWithRange:NSMakeRange(c+1, d-c-1)] forKey:[command substringWithRange:NSMakeRange(a+1, b-a-1)]];
        }
    }
    else{
        NSLog(@"COMMAND = %@", command);   
    }
             }
}


Objective-c... how I wish you were C++...
closed account (3hM2Nwbp)
Looks like fun torture. :\
Dear lord! This is almost as bad as moon speak D:
It's so ambiguous... I really wish everything was c++!
So uhh, just what the hell does it do?
Well if the server requests the iPod's unique ID, or username, the iPod will send it. The server can also send a special message to change the server IP and Port, and when it sends the reconnect message the client will be automatically redirected to the new server.

That is all.
well... yea i've got nothing.
Haha, I don't really even know how this is relevant to anything. Just thought I'd share my dislike of having to program everything in obj-c
Is it for your job?

edit: incidentally of all languages I've ever seen, that is by far the ugliest I've ever seen. I know that's a subjective view..but still. I have yet to see one that's more nauseating to me
Last edited on
It's for my iPhone app, my "job" is currently an assistant lab tech in the biology dept of my local college. This is for money though =)

I agree, it's very ugly.
Ahh the beauty of hybrid languages.
If Apple can lower the barrier to entry for indie developers they would have me as one of their developers but unfortunately they chose to price themselves out of the market for some developers.

A simple math. Annual renewable US$100 versus a one-time off US$25 to develop apps and list on their stores. Does their price calling justify the quality and stringent app checking? Maybe yes but that "promise" definitely does not justify the price based on my expectations and affordability.
Annual renewable US$100 versus a one-time off US$25
What are you comparing here?
I'm thinking he's comparing apple and google. The $100 price will hopefully be paid back with my apps, I'll let you know how it goes. Though I will admit I've seen a ton of crap apps on the google market vs the app store.

Need.To.Work.On.Server.
closed account (z05DSL3A)
Seraphimsan wrote:
edit: incidentally of all languages I've ever seen, that is by far the ugliest I've ever seen. I know that's a subjective view..but still. I have yet to see one that's more nauseating to me
ultifinitus wrote:
I agree, it's very ugly.
What in particular do you find ugly? While the code presented here is far from beautiful, it is not necessarily the fault of the language. Ugly code can be produced in any language.


Disclaimer: I do not mean to upset anyone and I not trying to start a flame war.
closed account (1yR4jE8b)
+1 Greywolf

Reminds me of a saying (paraphrasing) : "It's possible to write Fortran in any language"
@Grey Wolf

Its the over all syntax of the language. While any language can be written to have ugly code, I personally find the syntax of Objective-C to be, well, nauseating. I'm not exaggerating either. I legitimately can't read source written in Objective-C for very long without starting to feel ill.

That said, I know for a fact that if I had to write it for any extended period of time (say for work), I would desensitized to the aesthetics of the language.

edit: and as I said, I'm well aware this is a subjective view. I don't mean to upset anyone who enjoys the language.
Last edited on
In regards to the uglyness of the language, as an outsider knowing very little about Objective-C: The amount of repetition I see in this small sample of code suggests to me that the language is very verbose. Constant reuse of the words "command", "connection" and "NSString" tells me that this kind of thing is unavoidable. Could you imagine writting in C++ if NONE of the function attributes, type casts or operator overloads were remembered by the compiler? It would be a mess inside of a nightmare, it would be what I see here :p.

I mean no disrespect to the OP, in fact it's his reputation on this site that makes me want to blame the language or the API instead of the skill of the author.
Don't worry about disrespecting me =) My skill is far from perfect, this was quick and dirty and I don't expect it to be pretty. The language is just unfortunately not my preferred style...

I apologize for saying the language is bad, it's really not, and I like a lot of its features. In this case I was showing off my poorly written example of poor code... Some can be beautiful, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#import <UIKit/UIKit.h>

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

@class NetworkClass;

@interface CleanChatViewController : UIViewController <UITextFieldDelegate,UIWebViewDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate> {
	NetworkClass *connection;
	
	UIImageView *advancedButtonSeperator;
	UIImageView *simpeButtonSeperator;
	UIImageView *connectedImage;
	
	UIImageView *backgroundImage;
	UIImageView *sendBarImage;
	UIImageView *webViewBack;
	
	UIButton *buttonOne;
	UIButton *buttonTwo;
	UIButton *buttonThree;
	UIButton *buttonFour;
	UIButton *buttonFive;
	UIButton *buttonSix;
	UIButton *buttonSeven;
	UIButton *buttonEight;
	UIButton *buttonNine;
	UIButton *buttonTen;
	UIButton *buttonEleven;
	UIButton *buttonTwelve;
	UIButton *buttonThirteen;
	UIButton *buttonFourteen;
	
	UIWebView *webView;
	
	UITextField *outField;
	UITextField *serverIP;
	
	NSString *username;
	NSString *allText;
	
	UILabel  *localIP;
	UILabel  *message;
	
	UIScrollView *scrollView;
	
	NSThread *receiveThread;
	NSThread *sendThread;
    
        NSArray *blackList;
    
        NSMutableDictionary *settings;
	
	int idNum;
	
	BOOL quit;
	BOOL swap;
	BOOL simpleMode;
	BOOL isPortrait;
        BOOL leftLandscape;
}

-(IBAction) startConnecting;
-(IBAction) connectToIP;
-(IBAction) serverIPPressed: (UITextField *) sender;
-(IBAction) serverIPDone: (UITextField *) sender;
-(IBAction) sendButton;
-(IBAction) backgroundTouched;
-(IBAction) clearButton;
-(IBAction) closeButton;
-(IBAction) changeModeToAdvanced;
-(IBAction) changeModeToSimple;
-(IBAction) simpleConnectButton;
-(IBAction) simpleDisconnectButton;
-(IBAction) displayAllOnWebView;
-(IBAction) helpButton;
-(IBAction) newButton;
-(IBAction) mailButton;

-(NSString*) getLocalIP;
//returns the local ipv4 address

-(NSString*) makeCommand: (NSString*) toMakeCommandFrom;
//returns a string using my protocol for commands

-(void) appendTextFieldWithOptions: (NSArray *)options; 
//same as append from user only using an nsarray

-(void) receiveAndSetText; 
//This is the main receiving thread

-(void) setViewMovedVertical:(BOOL)movedUp; 
// when you select the bottom text field this moves the whole screen up

-(void) setViewMovedHorizontal: (BOOL)moved;
//same as above.

-(void) handleCommand: (NSString *) command; 
//handles commands from the server format (char 2)[cmd](char 4)

-(void) addToWebTextView: (NSString *)toAdd; 
//this actually adds and loads text to the webviews

-(void) changeWebTextView: (NSString *)toChangeTo; 
//this changes all of the text in the webviews

-(void) addInput: (NSString *)input byUser: (NSString *)user; 
//this changes the colors of the text and username

-(void) setAdvancedControlsHidden: (BOOL) toHide; 
//sets the server client close and clear buttons to toHide

-(void) setSimpleControlsHidden: (BOOL) toHide; 
//sets connect and new partner buttons to toHide

-(void) updateSimpleConnectDisconnectTo: (BOOL)connected; 
// sets advanced to !simple controls and simple controls to connected

-(void) updateSimpleConnectDisconnectAuto; 
// same as to connected but by checking the simple variable

-(void) updateBothWebViews; 
//this loads both webviews automatically (to prevent glitch at startup

-(void) showConfirmAlert: (NSString *)newMessage withTag: (NSInteger)newTag; 
//loads an alert with several options

-(void) setBlackList: (NSArray *)toSet;
//set banned words

-(void) didConnect: (BOOL) did;
//display a connect message, perhaps do other stuff in the future

-(NSArray *) getBlackList;
//returns banned words

-(void) readSettings;
//read all settings into the settings dictionary

-(void) saveSettings;
//save settings back to file

-(void) loadDefaultSettings;
//read all settings from the default file into the settings dictionary

-(BOOL) checkConnection;
//send 0 bytes. Just a quick method of testing connection


@property (nonatomic, retain) IBOutlet UITextField *outField;
@property (nonatomic, retain) IBOutlet UIImageView *connectedImage;
@property (nonatomic, retain) IBOutlet UIImageView *advancedButtonSeperator;
@property (nonatomic, retain) IBOutlet UIImageView *simpleButtonSeperator;
@property (nonatomic, retain) IBOutlet UIImageView *backgroundImage;
@property (nonatomic, retain) IBOutlet UIImageView *sendBarImage;
@property (nonatomic, retain) IBOutlet UIImageView *webViewBack;
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) IBOutlet UIButton *buttonOne;
@property (nonatomic, retain) IBOutlet UIButton *buttonTwo;
@property (nonatomic, retain) IBOutlet UIButton *buttonThree;
@property (nonatomic, retain) IBOutlet UIButton *buttonFour;
@property (nonatomic, retain) IBOutlet UIButton *buttonFive;
@property (nonatomic, retain) IBOutlet UIButton *buttonSix;
@property (nonatomic, retain) IBOutlet UIButton *buttonSeven;
@property (nonatomic, retain) IBOutlet UIButton *buttonEight;
@property (nonatomic, retain) IBOutlet UIButton *buttonNine;
@property (nonatomic, retain) IBOutlet UIButton *buttonTen;
@property (nonatomic, retain) IBOutlet UIButton *buttonEleven;
@property (nonatomic, retain) IBOutlet UIButton *buttonThirteen;
@property (nonatomic, retain) IBOutlet UIButton *buttonFourteen;
@property (nonatomic, retain) IBOutlet UIButton *buttonTwelve;
@property (nonatomic, retain) IBOutlet UILabel  *localIP;
@property (nonatomic, retain) IBOutlet UILabel  *message;
@property (retain) IBOutlet UITextField *serverIP;
@property (retain) IBOutlet UITextView *receiveText;
@property (retain) NSString *allText;
@end
@Lines 19-32: Objective-C / your APIs won't let you condense those into an array?

-Albatross
Pages: 12